3

I'm running GDAL 1.11.2, released 2015/02/10.

The following displays all the attributes in my shapefile on stdout:

/opt/gdal-custom/bin/ogr2ogr -f CSV /vsistdout/ foo.shp -sql "SELECT * FROM foo "

However, if I add the WHERE clause WHERE ST_Intersects(GEOMETRY,BuildCircleMbr(0, 0, 10000, 4326)) I get ERROR 1: Undefined function 'ST_Intersects' used.

What am I doing wrong?

3

Without knowing your dataset I can't be 100% sure, but I'd wager you can solve this by adding -dialect sqlite since ST_Intersects is a Spatialite SQL function.

Your command should be

/opt/gdal-custom/bin/ogr2ogr -f CSV /vsistdout/ foo.shp -dialect sqlite -sql "SELECT * FROM foo "
  • 1
    Ok that works. My next step was to use BuildCircleMbr, which required me to recompile gdal with --with-spatialite=yes – Justin Dearing Jul 6 '15 at 20:38
1

I guess that ST_Intersects(Geom1, Geom2) will test a spatial relationship between two elements and return a boolean (True or False), what you need here is probably ST_Intersection(Geom1, Geom2) if you want to create a geometry (resulting of the intersections of the two others passed in arguments).

(If it is ST_Intersects() that you need, it should probably be after the WHERE clause, like "SELECT * FROM foo WHERE ST_Intersects(Geom1, Geom2)")

(or maybe if you want to create geometry for self intersections you can try the SpatiaLite/LWGEOM function ST_SelfIntersections(Geom) but I'm not sure that you can call it using ogr2ogr, even with -dialect SQLite enabled)

  • I should have described what I really wanted to do. Was working on getting ST_Intersects() working at all first. – Justin Dearing Jul 6 '15 at 20:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.