15

Has anybody used Mapnik for rendering Maps from .net c# environment? I would like to use it to render maps in a desktop application developed under .net4. I found it the best open source map renderer tool, much more better, than the well known sharpmap, dotspatial (...). The 'only' problem is that it was written in C++ and Python and does not have a trivial way to use it from C#.

Do you know any .net Mapnik wrappers? Do you know any sample code?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Tom
  • 3,899
  • 22
  • 78
  • 137
  • Project at http://code.google.com/p/mapnikdotnet/ is empty - you might try emailing the author. – TrueWill May 28 '11 at 16:33
  • 1
    @TrueWill -- hmm, took a look at that just now. Looks like there IS some code there after all: http://code.google.com/p/mapnikdotnet/source/browse/#svn%2Ftrunk%2Fsrc%2Forg.capwin.gis.mapnik Project looks dead, but also seems like it was used in production for something. If the OP is willing to go to the trouble of compiling it... – Luke Winikates Jun 06 '11 at 06:39
  • I suggest that you post the question on gis.stackexchange.com (as well?) which is a specific site for this kind of questions. – steenhulthin Jun 07 '11 at 19:00
  • Perhaps you can check out Brutile http://brutile.codeplex.com/ It might offer what you need. – mzwaal Jun 14 '11 at 06:50

5 Answers5

5

I've just published my attempts in C# bindings.
They are available at: http://sourceforge.net/projects/mapniknet/

Community
  • 1
  • 1
michus
  • 91
  • 1
  • 4
  • Thx, I checked it out, trying to compile, I'll write my experiences! – Tom Sep 15 '11 at 10:52
  • So, I tried it but I could not make it work. I could not compile the c++ project. I added 3rd party libraries that I have seen in your code, but without any instructions it is hard for me. I took some way, but some errors coming again and again. Don't you have some text me about compiling? My problems now: where from can I get ltdl lib? Several error C3861: 'rint': identifier not found messages. Against which version of mapnik should I compile? I try 0.7.2 trunk.Severeal boost errors like Error 64 error C2780: 'boost::shared_ptr boost::make_shared(A1 &&)' : expects 1 arguments - 0 provided – Tom Sep 15 '11 at 12:14
  • + Error 123 error C2780: 'boost::shared_ptr boost::make_shared(A1 &&,A2 &&)' : expects 2 arguments - 0 provided . Thx for your efforts and help! – Tom Sep 15 '11 at 12:16
  • Here is my build log: http://www.megafileupload.com/en/file/326781/mapnikcbuild-txt.html – Tom Sep 16 '11 at 12:40
  • Recently I've added patches for MapNik sources is ext forder. They should be applied before building both mapnik dlls and bindings. Building was performed using boos 1.46.1. Older versions were not tested yet. – michus Sep 19 '11 at 08:56
  • Thx. And which Mapnik version do you use? – Tom Sep 19 '11 at 08:58
  • I made the patches, added some missing libs and incls, I made a lot of steps forward, but now dozens of unresolved external errors come, like Error 606 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall mapnik::building_symbolizer::~building_symbolizer(void)" (__imp_??1building_symbolizer@mapnik@@QAE@XZ) C:\Projektek\MapnikDotNetBeta\mapnik_c\mapnik_text_symbolizer.obj mapnik_c Log: http://www.megafileupload.com/en/file/327110/mapnik-c-log.html Don't know which lib and from where is missing, seems problems with symbol classes. – Tom Sep 20 '11 at 11:12
  • Was mapnik_c linked with mapnik.lib? It seems that was not. – michus Sep 21 '11 at 12:21
  • I don't have it from the latest (trunk) mapnik version. I have only mapnik.lib 0.7.1 – Tom Sep 21 '11 at 15:33
  • Bindings were made for the current version of mapnik residing in trunk. Older versions are not allowed. – michus Sep 22 '11 at 07:57
  • I see. But getting the last Mpanik lib - building in Windows - has not a trivial way, or do you have some good one to do it? I haven't found a recipe for this, there are a few experiments, but there is no one good and effective way. – Tom Sep 22 '11 at 09:46
  • I checked out your latest developments. I run the cmd file, built the external libs. It took a long time, all were successful. ...But at the end I get an error message when building mapnik project (from ext directory): Error 1 error LNK1104: cannot open file 'libboost_regex-vc100-mt-1_46_1.lib' C:\Projektek\MapnikDotNetBeta\ext\builds\LINK mapnik I don't have this file, only libboost_regex-vc100-mt-1_46.lib in C:\Projektek\MapnikDotNetBeta\ext\boost_1_46_1\stage\lib folder. What should I do? By the way: does your mapnik build/wrapper support SQLite as datasource? Thanks for your efforts!!! – Tom Sep 23 '11 at 01:00
  • I've just missed a pair of files. – michus Sep 23 '11 at 05:17
  • To recompile regex - remove it's libraries from stage. I'm using PostgreSQL data base so SQLite data provider was not built. – michus Sep 23 '11 at 05:25
  • Finally I could build it! Now I am trying to use .net wrapper, I try to load a map from my test xml that contains a shape file. When running the code I have 'Could not create datasource. No plugin found for type 'shape'' message. As I saw in your solution shape plugin exists and after building I have mapnik_shape library. WHat should I do with it? Thanks very much! – Tom Sep 23 '11 at 13:40
  • And what should I do to have SQLite plugin? I can see there are plugin projects in the solution, what about their project type, settings etc. Thanks! – Tom Sep 23 '11 at 13:45
  • I get also this 'no plugin found' message for PostGis – Tom Sep 23 '11 at 17:12
  • Okkey, I can load shapes by using MapnikCs.DatasourceCache.RegisterDatasources, so it is solved. My other questions still unsaved by me. – Tom Sep 23 '11 at 20:44
  • A minor bug in your files: allinone10.sln is missing from ext\icu\source\allinone folder, so patching can not complete. By converting allinone.sln solution to a VS2010 one and save as allinone10.sln is a working workaround. – Tom Sep 26 '11 at 14:27
  • 1
    First of all God bless you for your work, basically sqlite plugin works! A problem, that rtree (~spatial index) can not be used because of build params. I don't know which sqlite package do you use, but rtree was not built. Compilation should be changed: R*Tree module is included as part of the amalgamation but is disabled by default. To enable the R*Tree module, simply compile with the SQLITE_ENABLE_RTREE C-preprocessor macro defined. With many compilers, this is accomplished by adding the option "-DSQLITE_ENABLE_RTREE=1" to the compiler command-line.http://www.sqlite.org/rtree.html THANKS!!! – Tom Sep 26 '11 at 22:47
  • I have tested and rebuild sqlite in your solution, added SQLITE_ENABLE_RTREE=1 to the preprocessor definitions and rebuilt sqlite plugin, and now spatial indexing works. :) – Tom Sep 26 '11 at 23:08
  • 1
    Its performance is absolutely amazing! Nearly twice faster than my old solution based on Mapnik 0.7.1 and Python! – Tom Sep 27 '11 at 09:34
  • I tried your last changes, I could build everything successfully again, and SQLite plugin compilation with RTree index was OK. Install.cmd behaved strange this time, the prior version worked more clearly for me. I had to run patches after install.cmd by myself, install.cmd did not make the patches. I hope this info can help U. BTW I use XP professional, 32 bit and Visual Studio 2010, and I also test the result dlls on a 64 bit Windows Server 2008. Your wrapper works great on both systems in my test app, I rendered thousands of map images by it so far without any problem. – Tom Sep 27 '11 at 23:57
  • install.cmd was fine for Win7, but under Vista and older OSes it did not perform patching. This behavior was fixed in that commit. – michus Sep 30 '11 at 04:46
  • I ran the install.cmd and got a error building boost. "fatal error C1083: Cannot open include file: 'unicode/utyes.h'" I found it in "Visual Studio 2010\Projects\MapnikDOTNET\ext\icu\source\common\unicode". Wouldn't it just be easier to provide a prebuilt dll and the source. So people wouldn't have to build it just to get? – Donny V. Oct 10 '11 at 17:53
  • Looks like the previous error was because the file path was to long so I moved everything to C:\. The install.cmd ran fine but that only built the boost libraries. I then tried running the "mapnik-net.sln" solution and got a ton of errors. – Donny V. Oct 10 '11 at 20:17
  • It seems that patches were not applied. You can apply them manually. After it just rerun install.cmd – michus Oct 11 '11 at 06:09
  • There a couple problems with the install.cmd and apply_patch.cmd. Even on Win7 machines, when running batch commands, you need to surround any path with spaces with double quotes. So the patches weren't running. I got the patches to run. I then tried running the build on the solution again and still got errors. Is there anyway you can just post the dlls? – Donny V. Oct 12 '11 at 00:35
  • Can't build the last versions, dozens of patch error messages on XP 32 bit. – Tom Feb 09 '12 at 11:30
2

NET-Mapnik

You might want to give this a try. Its pretty recent and has a simple example with options to create vector tiles.
https://github.com/kernelsanders/NET-Mapnik

Community
  • 1
  • 1
Donny V.
  • 22,248
  • 13
  • 65
  • 79
2

Some good new about Mapnik-.Net integration:

"Another thing that will help Windows developers is a way to use Mapnik from .Net languages. Although a full .Net wrapper is too much work besides all the other issues, hopefully I can make a meaningful start and open the door for .Net developers to leverage Mapnik in their applications."

Source: Mapnik homepage http://mapnik.org/news/2011/jun/09/gsoc_2011_windows_build_system_introduction/

Tom
  • 3,899
  • 22
  • 78
  • 137
1

So, finally I hacked it. Not a nice solution, but it works at least. In nutshell it operates in the following way:

  • developed a python script, which takes parameters as command line arguments. (using python api of mapnik)
  • call this python script by shell fom c# code (Process)
  • after map image has been generated, I show it in SharpMap as a background layer

In case of any map refresh (zoom, pan) I regenerate 'mapnik map layer'. I have also some kind of cache, in which I can store generated maps, so I can make tricks by using earlier generated map images or pre-generate them (e.g. generate maps for the next zoom level when user uses zoom tool). I also use some asynchron calls to do this, so I can create 1-3 map images paralelly.

The weak part of this solution is the communication between python and c# modules. I could not find better than command line arguments + shell.

My solution works, mapnik is fast, can genarate my maps less than a sec.

If you have any advice on .net - python communication (NO ironpython, it is not suitable for manik api), pls write it here. Thx.

Tom
  • 3,899
  • 22
  • 78
  • 137
  • Some useful tips on .NET to Python communication can be found here: http://stackoverflow.com/questions/5682572/calling-python-from-net-in-a-loop-is-just-too-slow or you could create a webservice or socket and communicate with it from C#. – Samuel Dec 20 '11 at 11:15
-2

Do you know about TAO Project?
It is a .Net project that takes unmanaged opengle library to .Net Managed Form by calling DllIMport() in C#.

You must do it for Mapnik, simaliar to TAOFramework.net

TheGeekZn
  • 3,696
  • 10
  • 55
  • 91