[Shapelib] How to Extract line data with in given extents.

Frank Warmerdam fwarmerdam at gmail.com
Wed Feb 9 09:44:10 EST 2005


On Wed, 9 Feb 2005 19:06:08 +0530, Chandra Murali.S, ASDC Chennai
<chandramuralis at hcltech.com> wrote:
>  
> 
> Hi all, 
>         I'm new to Shape Library. I've started using this library and its
> helps me a lot in reducing my effort to reading and using the shape files.
> In this I faced a problem in finding the line data that exists in given
> extents. For example, I need to find the list of roads that falls within the
> bounding box. Is there any API is available to find this. 

Murali, 

If you look at the SHPObject structure you will see it has min/max
values for X, Y, Z and M.  So it is pretty easy to read all the
shapes and then compare the bounding box information for each
shape to your bounding box you want to search for to see if they
intersect.  Of course, this might identify some lines that aren't
actually in your bounding box, if they "wrap around" it to some 
extent. 

If want to do want to do fast searches, you will need a spatial index.
The CVS version of Shapelib has added support for loading and
saving a spatial index format, and using it for fast spatial searches. 
It is not the ESRI spatial index format though, it is another from 
MapServer. 

If you want to do precise spatial predicates to see what linestrings
cross a bounding box or many other kinds of complex spatial
operations, you might want to look at GEOS (geos.refractions.net).
But it is a fairly heavyweight. 

I also provide an OGR library that is "higher level" that shapelib
and supports Shapefiles amoung other things.   

  http://ogr.maptools.org/

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent


More information about the Shapelib mailing list