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

Hi Ellis,

> We are using Mapnik for data mapping of demographic data

cool :)

> 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. 
> When displaying the shapefile in Quantum GIS, it is displayed correctly: 
> Quantum GIS.png
> When displaying the shapefile using Mapnik, the label is in CA: Mapnik.png
> 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). 
> 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 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