1

I'm developing a website where I want to test which polygons from a shapefile intersect a given rectangle. Using PHP, I thought about using exec() function, calling a GDAL program, like ogrinfo. However, the following command line

ogrinfo -spat x0 y0 x1 y1 my_shape_file.shp

is not working how I thought it should. It always returns the name of the layer (after "Open of ... using driver 'ESRI Shapefile' successful."), despite the polygon is inside the given rectangle (x0,y0,x1,y1) or not. Anyway, I want the polygons intersecting the rectangle, not the whole shapefile. What is wrong in my usage? The instructions say nothing! (Of course I used actual coordinates instead of x0,y0...)

Other question: even when I get this to work, maybe using one of PHP GDAL extensions (version 5 or version 6) is faster, is it? And is it safer?

EDIT: I wasn't using the layer name (as returned from the previous command) after the shapefile name:

ogrinfo -spat x0 y0 x1 y1 my_shape_file.shp layer_name

Now I only need to know if PHP extensions are preferred over external commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.