Can I do map intersection on the fly?

Ken Lord kenlord at GMAIL.COM
Thu May 26 18:32:13 EDT 2005


Hi John,
 You in fact can do the intersection, and other spatial functions on the fly 
with the present version of MapServer ... if your data is held in PostGIS.
 I use the Windows CGI flavour of MapServer 4.4.2. The trick is to parse the 
proper SQL query together and use it in the DATA string for the layer.
 One way to do it is by creating a dummy map layer where the DATA string 
contains a query that returns nothing, and has the variable used in the 
substitution within the string. Then use some javascript/asp/whatever to 
alter the value of the substitute variable to use the function and the 
polygons of interest.
 For example, I have a data string that looks like this:
 DATA "the_geom from (SELECT * from surf_terrain %terrainname%) as foo using 
unique gid using SRID=26910"
 The value of terrainname defaults to a value that does not exist in the 
table, so the layer is blank. terrainname='WHERE type=XXX'
 The user can make the website highlight polygons in that layer by using a 
tool on the website that changes the value of terrainname, which is 
submitted in the html form, or through URL encoding.
 My example is simple, you could place the intersection function or whatever 
you want within that variable.
 We have another layer that on the fly shows forest fires that cross a 
pipeline. In this case the DATA string uses the 'crosses' function in 
PostGIS, and looks like:
 DATA "the_geom from (SELECT nt_FFIRES_a.* from nt_ffires_a, pipelin_l where 
nt_ffires_a.the_geom && pipelin_l.the_geom AND crosses(nt_ffires_a.the_geom, 
pipelin_l.the_geom)) as foo using unique gid using SRID=26910"
 Be warned! If you are going to do this, use spatial indexes where ever 
possible to improve performance, and even using spatial indexes, you may 
still find you've made queries that bog your website down too much if you 
aren't careful.
 The forest fire query above, running on an old P3 1ghz machine takes
2.6seconds with the index,
17.6 seconds without! ... and only 0.6 seconds on our new P4 server, using 
spatial indexes.

I'm sure those PHP'ers have great ways to do things too, but this method has 
worked well for us.
 Cheers,
Ken Lord
Vancouver BC

 On 5/26/05, Steve Lime <steve.lime at dnr.state.mn.us> wrote: 
> 
> You can't do that with MapServer as it sits. The GEOS support added for 
> 4.6 will allow this sort of stuff via MapScript although I haven't added 
> the intersection operator yet (only buffers and convex hulls are supported 
> at the moment). Are you using MapScript? If so, I could look into quickly 
> exposing an intersection method for a shapeObj.
> 
> e.g. $intersection = $shape1->intersect($shape2);
> $intersection->draw(...);
> 
> Steve
> 
> >>> John Kim <jkim at SCIENCES.SDSU.EDU> 05/26/05 12:34 PM >>>
> Is it possible to use Mapserver to display an intersection between two 
> polygons? I have two polygon shape files, and I'd like to display the 
> intersection of a polygon from one shape file with the polygon from the 
> other shape file. (The specific polygons are chosen on the fly according to 
> input from our network of sensors).
> 
> Thanks.
> 
> -John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050526/6796f9bc/attachment.html


More information about the mapserver-users mailing list