On 1/18/2011 8:52 AM, ZhaoYanli wrote:
Hi All:
I am planning to use "Openlayer+PHP+PostGIS" platform to build my map
query function.
First, users click on the map, Openlayer can get the lon/lat information.
Then, combine with the lon/lat info and other user specific query
requirements, I can build the SQL query from PostGIS using PHP
I am wondering how could I get the correct geometry ID of point, line or
polygon? Since what I can get from Openlayer is only lon/lat.
Thanks a lot
I do the same thing, but with perl. I looked up in the mapserver cgi
code how it figured out where the click point was on the map, and I
converted it to perl+PostGIS use:
When a user click's on the OpenLayer's map, I eventually get to this:
sub getFeatureInfo
{
my ($owreq, $xmap) = @_;
my($q);
my $bbox = $owreq->getValueByName('bbox');
my($x1, $y1, $x2, $y2) = split(/,/, $bbox);
my $cx = $owreq->getValueByName('x');
my $cy = $owreq->getValueByName('y');
my $width = $owreq->getValueByName('width');
my $height = $owreq->getValueByName('height');
#define MS_CELLSIZE(min,max,d) ((max - min)/(d-1))
#define MS_IMAGE2MAP_X(x,minx,cx) (minx + cx*x)
#define MS_IMAGE2MAP_Y(y,maxy,cy) (maxy - cy*y)
#cellx = MS_CELLSIZE(map->extent.minx, map->extent.maxx, map->width);
#celly = MS_CELLSIZE(map->extent.miny, map->extent.maxy, map->height);
#point.x = MS_IMAGE2MAP_X(point.x, map->extent.minx, cellx);
#point.y = MS_IMAGE2MAP_Y(point.y, map->extent.maxy, celly);
my $cellx = (($x2 - $x1)/($width-1));
my $celly = (($y2 - $y1)/($height-1));
$cx = $x1 + $cellx * $cx;
$cy = $y2 - $celly * $cy;
my $pt = "POINT($cx $cy)";
my $sql = 'select pin '
." from $xmap.getpin, GeomFromText(\$1, -1) as g "
.' where the_geom && g order by distance(the_geom, g) limit 1 ';
$q = $db->prepare($sql, {pg_async => PG_ASYNC});
$q->execute($pt);
the commented out code is from one of mapserver .c file. in the end $pt
is what I use to query PostGIS.
$owreq is from new mapscript::OWSRequest(), which php should have similar.
Hopefully this is what you were looking for.
-Andy
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users