Record count
Sean Gillies
sgillies at FRII.COM
Fri Jan 7 09:21:47 PST 2005
On Jan 7, 2005, at 10:34 AM, Abe Gillespie wrote:
> Is there a better way to get the total number of records in a shapefile
> than query for all records and getting the result count a la:
>
> $l->queryByAttributes("any_field", "/\w*/", MS_MULTIPLE);
> $cnt = $l->getNumResults();
>
> I realize you can use shapefileObj::numshapes, but this doesn't always
> work for me. I don't want to use hard paths and have tried it like:
>
> $path = $map->shapepath.$layer->data;
> $file = ms_newShapefileObj($path, -1);
> $cnt = $file->numshapes;
>
> This works on some sites and not on others. I remember reading
> something about Mapscript changing the current working directory. I
> think this is causing me issues as I keep my map file in "etc" and the
> HTML files one directory above that.
>
> Thanks.
> -Abe
>
>
A queryByRect will be faster than an attribute query if you have a
mapserver shptree index on your shapefiles. If you were using Python
mapscript you could also use the Python shapelib module or OGR's Python
module. In other languages, try an XBase module on the .dbf file.
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list