2

I am trying to use the sqlite symdifference function in windows command line with ogr but can't seem to get the syntax right. Here is what I have:

ogr2ogr -dialect sqlite -sql "select symdifference(a.geometry, b.geometry) from shp1 a, shp2 b" output.shp E:\temp\shp1.shp E:\temp\shp2.shp

I think there is an issue with how am I referencing the 2 source files (shp1 and shp2) at the end. Is it possible to run this function from command line, and if so how should the syntax be adjusted?

1 Answer 1

2

How to use JOIN is documented in http://www.gdal.org/ogr_sql_sqlite.html but the syntax may not be obvious.

Here we have shapefiles "a" and "b"

enter image description here

This is the command for ogrinfo (same -sql works for ogr2ogr). Windows needs back slash escaping for inner double quotes, I am not sure what is the correct syntax for Linux.

ogrinfo -dialect sqlite -sql "select st_symdifference(a.geometry,b.geometry) from a JOIN \"b.shp\".\"b\" as b" a.shp

The result as WKT

MULTIPOLYGON ((( 241 346, 241 545, 381 545, 381 346, 241 346 )), (( 381 346, 512 346, 512 545, 381 545, 381 585, 596 585, 596 291, 381 291, 381 346 )))

and as an image

enter image description here

2
  • thanks for your answer on this. When I try it, I get an error: cannot find layer b. I am in the directory where the b shp exists and I know the name is correct so not sure what the issue is
    – kflaw
    Commented Mar 15, 2018 at 20:56
  • What is the name of your shapefile? The syntax is "store"."layer" and with shapefiles names of store and layer are the same. Like " my_shapefile.shp"."my_shapefile" as b.
    – user30184
    Commented Mar 15, 2018 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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