[Mapserver-users] queryByRect of a PostGIS layer

Charlton Purvis cpurvis at asg.sc.edu
Thu Apr 24 14:03:40 EDT 2003


My subject heading should hopefully say it all:  I want to pull data
back from my PostGIS layer based on a rect.  My subject heading might
also indicate that I'm far out in left field and that I'm a complete
moron.

I've looked through the usergroup list, and I really can't find a
clear-cut answer.  I've seen how to get to data that hides in
shapefiles, and, believe it or not, I *am* a database monkey.  But I
think I'm missing an important piece of the puzzle.

Let's say that I want to do something like this in my .php:

$rect_extents = ms_newRectObj();
$rect_extents->set('minx',-81);
$rect_extents->set('miny',31.5);
$rect_extents->set('maxx',-76.9992);
$rect_extents->set('maxy',35.0008);
$layerObj->queryByRect($rect_extents);
echo "Num results = " . $layerObj->getNumResults() . " for " .
$layerObj->name;

OK, so far so good since my .map file looks like this:

  LAYER
    CONNECTION "user=postgres dbname=myGISdb host=localhost"
    CONNECTIONTYPE POSTGIS
    NAME "bathy"
    STATUS ON
    TYPE LINE
    TEMPLATE "dummy.html"
    CLASS
      COLOR 255 0 0
    END
  END

Wow!  I end up w/ an actual number for getNumResults.
  Num results = 739 for bathy

So now I want the results themselves.  If I were using shapefiles, I
believe that 
  layerObj->open($map->shapepath); 
would do the trick, but, not surprisingly, it bombs:  
  Wrong parameter count for open().

It sort of makes sense to me that it would bomb:  I'm not dealing w/ a
shapepath for this layer, per se, but at the same time, I wouldn't have
been surprised if it *had* worked since the PostGIS layers seem
transparent to MapServer for the most part.

That being said, how do I get my data back?  Do I need to simply get to
the data via magical SQL queries and fuhgetabout MapScript?  I doubt it.
There's got to be a MapScript trick to get me going.

Also, exactly how many hits am I making?  Seems like a lot.  (1) count
the number of records, and (2) go through them one by one to get the
meat.  But I might be completely off base here.  How about a CURSOR to
step through the returned rows?

If I understood a little more clearly what was going on (perhaps
everything is loaded into the objects, and the database hit only occurs
once) . . . well . . . I'd understand it a little more clearly!

Infinite thanks.

Charlton
 
 
 
Charlton Purvis
(803) 777-8858 : voice
(803) 777-8833 : fax
cpurvis at sc.edu
 
Advanced Solutions Group
Department of Physics and Astronomy
University of South Carolina
Columbia, SC 29208




More information about the mapserver-users mailing list