Mapscript: How to get all shapes from a layer

Sean Gillies sgillies at FRII.COM
Wed Nov 17 10:33:30 EST 2004


On Nov 17, 2004, at 8:06 AM, Ivano Picco wrote:

> 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
>

Hi Ivano,

There is not yet a method to get all features from a layer, or even to
iterate efficiently through query results.  For now, I suggest you
access
your features tables directly using the oracle DBI or use an OGR driver
for other data types.

I'm willing to help you with developing this new feature.  Will you
enter a new enhancement issue in the MapServer bugzilla?  If you make
it under the mapscript-swig component, I will be alerted to it.  It's
too late for this enhancement to be in the next 4.4 release, but we
could start to work on it for the next one.

cheers,
Sean



--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies



More information about the mapserver-users mailing list