[mapserver-dev] Ok, one more labeling sample...

Paul Ramsey pramsey at cleverelephant.ca
Wed Sep 17 18:40:31 EDT 2008


V. impressive Steve, great putzing!

P

On Wed, Sep 17, 2008 at 3:35 PM, Steve Lime <Steve.Lime at dnr.state.mn.us> wrote:
> As I putzed with the polygon label point code I realized that the line intersection and centering was screwing up some optimal placements based solely on the center of gravity computation. You really only want to go to that extreme if 1) the CoG is outside the polygon or 2) it's near the edge of the polygon. So, I've accounted for those and added a switch that centers the label on the either a vertical or horizontal line depending on the CoG departure from the bbox center point.
>
> Anyway the algorithm looks like so:
>
> 1) compute CoG of largest (in terms of area) outer ring
> 2) if that point falls within the polygon
>  a) compute shortest distance to polygon
>  b) if distance is greater than 10% of largest bbox dimension then quit, your done
>  c) if not, then point is near an edge go to step 3)
> 3) intersect a vertical or horizontal line with the polygon and the CoG and find the longest segment, using the mid-point of that segment as the label point
>
> With the U.S. states shapefile 9 polygons (e.g. FL, LA) are close to the edge and fall through to step 3. Not sure what the right value is there. The results are quite nice however. I've attached images from this method and the current 5.2 output. Again, I can supply a patch if anyone would like to try it. I'll supply before and after for a few of the test datasets folks sent in separate messages.
>
> Steve
>
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>
>


More information about the mapserver-dev mailing list