[mapserver-users] Re: [postgis-users] Google Maps API with PostGIS

Stephen Woodbridge woodbri at swoodbridge.com
Mon May 30 23:19:37 EDT 2011


On 5/30/2011 8:55 PM, Ahmad Aburizaiza wrote:
> Hello Stefan,
>
> Thank you for your reply. I will answer your questions :
>
> 1. the user selects a polygon(s), how does this happen? where are the
> polygons?
>
> The polygons are in a PostGIS table. I want the users to select the
> polygons from a list.
>
> 2. create a convex hull from the select polygons : 3. now you have a
> convex hull :
>
> I just need a convex hull to be drawn or displayed on top of the map. I
> do not need to store it anywhere.
>
> I have a question. You said "but if you have less then passing the
> features to OpenLayers and rendering them as a vector layer is probably
> fine". By passing the features, do you mean that I do not need a WMS?
> Can you give me an example please.

Write a php ajax function that queries your data base for the buildings 
and returns an XML or GeoJSON doc to OpenLayers and load the features 
into a layer over you google layer.

http://dev.openlayers.org/releases/OpenLayers-2.10/examples/xml.html
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/geojson.html
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/google-v3.html
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/
http://www.openlayers.org/

You can set the layer up so on every pan/zoom you re-query the database 
based on the view port extents to get the features you need. If the 
total feature count is under 500, you can probably just load them all 
initially and not issue additional requests.

If you pass the gid of each feature to OpenLayer and display it as a 
vector layer, you can then use the select tool on that layer  so when 
the user selects the building they will get highlighted. Then add a 
button to get the convex hull, and when this button is pressed get the 
list of gid of the selected objects and issue an ajax request to your 
PHP with the list of gids and have it run sql like:

select astext(st_convexhull(st_collect(the_geom))) from buildings where 
gid in (<list from client>);

and have it return the result. Then you can all that as a feature to the 
your vector layer or a results layer. You will probably also want to add 
a clear button to clear the selected buildings and convex hull.

At this point, you might want to take this over to the openlayers list 
because you can probably do all this with using mapserver. Also you 
should look at the source code of the openlayers examples, they are 
designed to be very simple so you can use them as spring board to 
building bigger applications.

-Steve

> Please let me know.
>
> Thank you,
>
>
>
> On Mon, May 30, 2011 at 4:12 PM, Stephen Woodbridge
> <woodbri at swoodbridge.com <mailto:woodbri at swoodbridge.com>> wrote:
>
> I think you need to think through the whole flow of this application and
> answer questions like:
>
> 1. the user selects a polygon(s)
> how does this happen?
> where are the polygons? in the client, or on the your server, or on
> google's server?
> How did they get display on the page because this will determine what
> the selection process needs to be.
>
> 2. create a convex hull from the select polygons
> if you are creating the convex hull in postgis, then you need to get the
> selections to your postgis server.
> where is the postgis server?
> Where are the selected polygons?
>
> 3. now you have a convex hull
> what do you want to do with it? display it on the map? do you want to
> draw it as a vector object or draw it as an image overlay? Do you need
> to store the convex hull for later use? Where do you plan to store it?
>
> As you know there are many ways to skin a cat. Without more information
> on your specific use case, I would implement this using OpenLayers and
> not the Google API (in part because it open javascript api for mapping
> and feature manipulation and I know it better than the Google API), and
> I would probably write a simple PHP ajax handler to interact between the
> web application and the database. I assume the building are already
> loaded in postgis. If you need more then say 500 building display on the
> screen them you will probably want to draw them via mapserver as an
> image overlay, but if you have less then passing the features to
> OpenLayers and rendering them as a vector layer is probably fine.
>
> Hope this helps,
>   -Steve W
>
>     On 5/30/2011 1:51 PM, Ahmad Aburizaiza wrote:
>
>         Hello all,
>
>         I am fairly new to PostGIS and I have to work on a project for
>         my PhD. I
>         hope you can help me. I want to build a web map where the user can
>         select a building or more than one from a layer on top of Google
>         Maps
>         API and the code should create an automatic convex hull from the
>         set of
>         points generated from the selected polygon(s). I am not sure on
>         what to
>         use but I have general ideas and I do not know which is the best :
>
>             * Do I use Google Maps API and PostGIS without needing a WMS
>         or WFS?
>             * Do I have to use with Google Maps API a WMS or a WFS?
>
>         And if someone has beneficial samples I can use to build the
>         website, I
>         would really appreciate it.
>
>         Thank you in advance.
>
>
>



More information about the mapserver-users mailing list