Mapscript: How to get all shapes from a layer

Ivano Picco ivano.picco at AQUPI.TK
Wed Nov 17 10:06:52 EST 2004


Hi list,
Thanks a lot for your help in the past days. I've another question for you:
I have to get geometry of all shapes from a layer with a perl script. Since
now I've used queryByRect and two nested loops to get the points like
snipplet code below:

[...CUT...]
$map->prepareQuery();
my $return=$layer->queryByRect($map, $map->{extent});
my $results=$layer->getResults();
if ( $results!=mapscript::MS_FAILURE ){
 my $i=1;
 $layer->open();
 while ( $i<$results->{numresults} ){
         my $result= $results->getResult($i);
  my $shape= $layer->getFeature($result->{shapeindex},$result->{tileindex});
  for($j=0; $j<$shape->{numlines}; $j++) {
   my $part = $shape->get($j);
   for($k=0; $k<$part->{numpoints}; $k++) {
    my $point = $part->get($k);
[...CUT...]

With this I have to get data from db many times: the first during
queryByRect to build the resultCache, the others to retrieve every single
shape. This approach takes about ten second to get 4886 shapes from an
Oracle Spatial connection. With a drawQuery it tooks only 2 second to
retrieve data and draw image. I look deep into source code to find how to
get data one time only and retrieve geometry directly from memory (like draw
image code or queryBy...). I found this two function: msLayerWhichShapes and
msLayerNextShapes. The first it's what I need to get all shapes, the second
could be used to get single shape from memory, but they aren't wrapped on
perl mapscript. I try to put it into SWIG wrapped code, but I made some
mistake,  and now my script doesn't run. However, I think this it's the
wrong way.
After some day spending time on documentation I'm back to you.
Are there any methods to use this two functions? or what's the right method
to get all geometry from a single layer?
For developer: Do you think it's more simple to wrap the unwrapped functions
than spending time coding a new method?

I hope you could help me, sorry for my english,
Thanks a lot,
Ivano Picco



More information about the mapserver-users mailing list