[mapserver-users] Need help with shpxy centriod in template file

Kent Richards info at kentrichards.net
Fri Apr 12 09:24:25 PDT 2013


Forgot to cc the list…

Thanks Steve,

The most visible problem is that the centroid values I'm getting are the same for all shapes in the output.  It's a United States map, and for all states in the result set, the "centroid" comes out to the same point, somewhere around Wyoming.

The rest of the output is expected:  a set of vertices for each shape that correctly renders the imagemap.

But, since the centroid is supposed to be a simple center of the bounding box, it probably won't do what I need anyway.

Thanks,

Kent


On Apr 12, 2013, at 8:40 AM, Lime, Steve D (MNIT) wrote:

> The centroid in the shpxy code is very basic and not a true centroid, it's just the mid-point of the bounding box of shape in question. It really wouldn't need to be this simple I think. The computation of that value is done on the raw shape and converted to image coordinates. I'm guessing it's the way the "centroid" is computed that is causing the problem?
> 
> Steve
> 
> -----Original Message-----
> From: mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Kent Richards
> Sent: Sunday, March 31, 2013 1:13 AM
> To: mapserver-users at lists.osgeo.org
> Subject: [mapserver-users] Need help with shpxy centriod in template file
> 
> When using the imagemap output in mapscript, I'm trying to get the center of the shapes using [shpxy precision=0 proj=image centroid=true].
> 
> Perhaps the first most obvious question is: am I misunderstanding what "centroid" means in this case?  I thought it meant the geometric center of the shape (of each shape, in this case).
> 
> I have an imagemap TEMPLATE file with this declaration:
> 
>> <!-- MapServer Template -->
>> <area class="[shpxy precision=0 proj=image centroid=true xh="x" xf="-" yh="y" sh="center-"]" shape="poly" coords="[shpxy precision=0 proj=image]" href="http://my.url/mypage.cfm?ID=[state]" title="[state]" alt="[state]">
> 
> 
> The [shpxy centroid-true...] part returns "center-x367-y128" *for each shape* (the raw coords are 367, 128).
> 
> 367, 128 is not in the center of the image, nor in the center of most of the shapes.
> 
> The other shpxy declaration in the template -- for the coords attribute -- seems to behave as expected.
> 
> Any ideas what I'm doing wrong, or is this a bug?
> 
> I know I can rig a convoluted means to return just the polygon points and calculate a center of sorts myself, but I'd like to just use the mapserver feature if it works.
> 
> Thanks,
> 
> Kent
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
> 
> 



More information about the mapserver-users mailing list