[Mapserver-users] PostGIS Spatial Selections in MapScript

Benjamin Wragg bwragg at tpg.com.au
Wed Feb 5 17:49:21 EST 2003


Hi all,

I'm currently building a web site which in part allows users to specify
an area on the screen to select features in a PostGIS layer. The
selected features need to be displayed on the map in a layer and a list
of the selected features displayed on the web page. The area that they
define gets created as a feature in a PostGIS layer. I was wondering
what methods people recommend to accomplish this in PHP/Mapscript.

In know that in psql I can use the following sql statement:

    select * from countries where the_geom &&
GeometryFromText('POLYGON((0 0 , 20 0, 20 20, 0 20, 0 0))',-1);

and get small portion of the worlds countries returned correctly.

To implement this sql in Mapsearch, what would be the way to go about
it? The idea I came up with is shown below. It doesn't work but am I on
the right track?

	$layer=ms_newLayerObj($GLOBALS['map']);
	$layer->set("connectiontype","postgis");	
	$layer->set("connection","host=localhost dbname=dbname user=user
password=password");
	$layer->set("data","the_geom from postgislayer");
	$layer->setFilter("the_geom && GeometryFromText('POLYGON((0 0 ,
20 0, 20 20, 0 20, 0 0))',-1)");
	$layer->set("name", $this->layerName);
	$layer->set("type", MS_LAYER_LINE);
	$class=ms_newClassObj($layer);
	$class->set("name", "Selected Features");
	$colorId=$GLOBALS['map']->addColor(255,0,0);
	$class->set("color", $colorId);
	$class->set("size", 5);
	$layer->set("status", MS_ON);

Thanks,

Benjamin Wragg




More information about the mapserver-users mailing list