I tried using the new algorithms and they were better for Alaska, but I really don't like what they do to other state placements (screenshot).

I went back to some older versions of the shape files and saw that a month ago Alaska was labeled correctly, so I'm asking my GIS guy to see what he can do with the shapes file. Sometime in his editing, something went wrong.

Thanks for your help. I think we'll be good to go.

- Ellis

-------- Original Message --------
Subject: Re: [Mapnik-users] Misplaced polygon labels
From: Dane Springmeyer <[email protected]>
To: Ellis Miller <[email protected]>
CC: [email protected]
Date: 11/22/2011 2:40 PM

On Nov 22, 2011, at 12:28 AM, Ellis Miller wrote:

Thanks so much! Comments below.

-------- Original Message --------
Subject: Re: [Mapnik-users] Misplaced polygon labels
From: Dane Springmeyer <[email protected]>
To: Ellis Miller <[email protected]>
CC: [email protected]
Date: 11/22/2011 12:55 PM

On Nov 21, 2011, at 10:28 PM, Ellis Miller wrote:

Hi Ellis,

We are using Mapnik for data mapping of demographic data

cool :)
It's been fun working with maps. When I showed the feature to my 9-year-old son, he started playing with the various demographic maps for a while and ended up with a comment "I'd enjoy programming something like this!" The next day he wanted to run the maps again. :-)

Rock on.


and are having a bit of a problem with the placement of Alaska's label for our State shapefile (it's showing up in California!).

Sorry about that. MultiPolygons are bit tricky and we've only recently started to work on getting placement more robust for them: https://github.com/mapnik/mapnik/issues/812

I think it may be a problem in the shapefile, but I don't know how to fix it.

Unlikely a problem in the shapefile, but nevertheless it needs to be fixed in the shapefile.

I've been a developer for quite some time, but I'm new to the GIS world.
  1. When displaying the shapefile in Quantum GIS, it is displayed correctly: Quantum GIS.png
  2. When displaying the shapefile using Mapnik, the label is in CA: Mapnik.png
  3. I could provide the shapefiles we are using -- these are based on public shapefiles, but were edited by a GIS guy (primarily moving AK, HI, PR and merging polygons so that we get a single label per state).
  4. We are using mapnik in a C++ dll (see code snippet below). 

The label was positioned correctly in Mapnik before the GIS guy merged polygons.


Right, it is the merging that throws off the default centroid algorithm in mapnik.

So, your options are either:

1) break back out the polygons, or at least one. You could potentially leave all of the sub parts of alaska merged except break out just the large main landmass. Add a column to the attributes that indicate you want it labeled and then filter on that attribute, using a mapnik Filter in your rule to catch only that row (representing the big polygon you want labeled)

2) Tweak include/mapnik/geometry.hpp to use a different centroid algorithm that supports multi-geometries better. Depending on your mapnik version there may be a few already available in the code you could use (the change would need to be made in src/agg/process_text_symbolizer.cpp to reroute to use them).

Since you mention you are on windows I presume that tweaking and recompiling mapnik may not be in your cards, so let me know if I can help you with option #1 a bit more.

I'd be interested in pursuing #2.

Didn't see that coming :)

We are compiling in C++, though it wasn't easy at first!

lol

When were the new algorithms introduced? I think we're using 0.7.1, but hopefully it won't be too bad to upgrade to 2.0.0.

Or just backport them first just to make sure they do what you need. There is nothing that needs to be specific to Mapnik 2 about them. Some stuff changed around how we store geometries in Mapnik 2, so they would not be a simple copy and paste, but should not be too bad:


Just note - they are not used anywhere yet and only very lightly tested.



I spent a bunch of time reading forums. I found a suggestion on http://lists.berlios.de/pipermail/mapnik-users/2011-July/004437.html to use placement="interior", however, in C++ I don't see any Interior options for set_label_placement.

That was only added in the Mapnik 2.0.0 release. Anyway, it also suffers from not being robust in the face of multigeometries.

Any suggestions what I should change on my side or how to track down the problem in the shapefiles?

Thanks,
Ellis Miller


Code snippet for setting labels:

rule_type vTextRule;
text_symbolizer vTextSymbolizer((LPCTSTR)sColumnInDBFForShowLabel, (LPCTSTR)sFontName_c, iFontSize, color(0, 0, 0));
vTextSymbolizer.set_avoid_edges(true);
vTextSymbolizer.set_label_placement(POINT_PLACEMENT);
vTextRule.append(vTextSymbolizer);

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users




_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to