Error dissolving shapefile with ogr and SQLite

419 views Asked by At

I'm trying to dissolve a shapefile based on this question and that instruction. However, when I run my line of code:

ogr2ogr "c:/working/testing/dissolve.shp" "c:/working/testing/test.shp" -f"ESRI Shapefile" -dialect sqlite -sql "SELECT ST_Union(geometry) FROM 'test'"

I get the following Error:

ERROR 1: In ExecuteSQL(): sqlite3_step(SELECT ST_Union(geometry) FROM 'temp_2'): SQL logic error or missing database

What am I missing?

EDIT: The "Dissolve" algorithm of QGIS works perfectly fine (not the one which uses ogr2ogr, but their own). Is there any magic I don't understand?

1

There are 1 answers

0
s6hebern On BEST ANSWER

Alright, I sorted it out by myself. The reason for the failure was that within the shapefile, some features had been marked as deleted, as per this error message when reading single features:

ERROR 1: Attempt to read shape with feature id (0), but it is marked deleted.

I was now able to work around this by copying the shapefile, which also repacks it and deletes all features that are marked as such. With this new copy, the initial line of code works perfectly fine.