[mapserver-users] Finding the centroid given the feature

Varun saraf vsaraf.gmu at gmail.com
Tue Jun 2 13:16:15 PDT 2009


Thanks a lot Steve. I am able to use the itemquery to fetch the other
attributes correctly but somehow, the center of polygon isn't working
right. Its returning to me, the co-ordinates that are outside the
bounds of the mapping application. All my data is in the actual
geographic co-ordinate system followed by Google maps and it returns a
latitude/longitude pair corresponsing to some place in Antarctica. Any
idea on what might be wrong?

On Tue, Jun 2, 2009 at 1:50 PM, Steve Lime <Steve.Lime at dnr.state.mn.us> wrote:
> Yes, you'd need to create a template for that. You could return JSON, XML, csv or whatever. This would
> be the most straightfoward using 5.2 or ideally 5.4.1 (due out today) and the new style templates. You
> could create a template output format to use like so:
>
> OUTPUTFORMAT
>  NAME 'geom_center'
>  DRIVER 'TEMPLATE'
>  MIMETYPE 'text/plain'
>  FORMATOPTION 'FILE=geom_center.tmpl'
> END
>
> where geom_center.tmpl might look like:
>
> <!-- MapServer Template -->
> [shpmidx],[shpmidy]
>
> and your query would look like:
>
> http://.../cgi-bin/mapserv?map=foo.map&...itemquery stuff...&qformat=geom_center
>
> Steve
>
>>>> On 6/2/2009 at 12:17 PM, in message
> <6db14d250906021017kb56f49ak36b4d0e4be417152 at mail.gmail.com>, Varun saraf
> <vsaraf.gmu at gmail.com> wrote:
>> Center of the geometry works perfect. I need to get access to any
>> point inside the polygon feature. I believe I can use an itemQuery on
>> mapserver to query the attribute but how does mapserver return the
>> center point? Do I need to create an HTML template for that too?
>>
>> On Mon, Jun 1, 2009 at 4:11 PM, Steve Lime <Steve.Lime at dnr.state.mn.us> wrote:
>>> MapServer templates can produce a center point for a geometry but it's not a
>> true centroid but those
>>> aren't guaranteed to be "in" the polygon. MapScript could be used as well I
>> suppose. In either case you'd
>>> send a lookup request to the CGI or MapScript, do an attribute query and
>> return whatever you'd need.
>>>
>>> Steve
>>>
>>>>>> On 5/29/2009 at 9:32 AM, in message
>>> <6db14d250905290732pb01747wce200eddfe73d1b2 at mail.gmail.com>, Varun saraf
>>> <vsaraf.gmu at gmail.com> wrote:
>>>> I am using mapserver 5.0 with google maps and the data source is the
>>>> US Census tracts as shape files and dbf files.
>>>>
>>>> On Thu, May 28, 2009 at 2:12 PM, Steve Lime <Steve.Lime at dnr.state.mn.us>
>>>> wrote:
>>>>> What version are you using? What data source?
>>>>>
>>>>> Steve
>>>>>
>>>>>>>> On 5/28/2009 at 10:01 AM, in message
>>>>> <6db14d250905280801q3660a6a7ycbcd5f5a238c595c at mail.gmail.com>, Varun saraf
>>>>> <vsaraf.gmu at gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I know mapserver uses a point-in-polygon method to find a feature
>>>>>> given a set of co-ordinates, but can it do the same thing reversed?
>>>>>> For example. Each polygon I draw has a number associated with it which
>>>>>> is in a "dbf" file with the same name as the "shp" file that mapserver
>>>>>> uses to draw the polygons. My current map file allows me to fetch that
>>>>>> unique number whenever I pass the co-ordinates of any point inside
>>>>>> that polygon (mapserver uses the point-in-polygon method to fetch me
>>>>>> the polygonID). The query I use is
>>>>>>
>>>>>> http://127.0.0.1:8123/cgi-bin/mapserv.exe?&map=C:/ms4w/apps/workshop-5.0/testMa
>>>>>> p.map&mode=query&mapxy=-77.098617
>>>>>> 38.87795
>>>>>>
>>>>>> where mapxy keeps changing based on the user's click. The html
>>>>>> template I send just has the variable name [polygonID] which helps me
>>>>>> get the polygon ID of the point I specify in the mapxy variable. Now,
>>>>>> is there a way in which I can send this polygonID to mapserver and get
>>>>>> hold of any point (perhaps the centroid) inside of this polygon? Can
>>>>>> someone point me in the right direction here?
>>>>>>
>>>>>> Thanks a lot.
>>>>>>
>>>>>> -Varun
>>>>>> _______________________________________________
>>>>>> mapserver-users mailing list
>>>>>> mapserver-users at lists.osgeo.org
>>>>>> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>>>>>
>>>>>
>>>> _______________________________________________
>>>> mapserver-users mailing list
>>>> mapserver-users at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>>>
>>>
>> _______________________________________________
>> 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