I have been trying to dissolve a shapefile with more than 38000 rows. I used query as follows

ogr2ogr -f "ESRI Shapefile" dissolved.shp Barangays.shp -dialect sqlite -sql "select ST_union(Geometry),* from input  GROUP BY concated"

It gave me error that geometry is invalid because of self-intersecting polygons.

I found out there are 86 features which have invalid geometries using QGIS. I tried Make Valid tool as suggested in this question. But this is also not working, giving error undefined symbol, which I couldn't understand. So I decided to validate using ogr2ogr and after searching through google I tried this query

ogr2ogr -f "ESRI Shapefile" valid_barangays.shp Barangays.shp -dialect sqlite -sql "select Geometry.MakeValid(),* from Barangays"

It gave me this error

ERROR 1: In ExecuteSQL(): sqlite3_prepare(select Geometry.MakeValid(),* from Barangays):
  near "(": syntax error

How can I solve this problem?

I also imported my shapefile using ogr2ogr in phpmyadmin mysql. It saved geomtry column as [geometry some_number B]. I am not able to query. I always give error function not exist.

  • What about using QGIS ?
    – Shiko
    Jul 30, 2016 at 15:39
  • @shiko As an automated process? May 1, 2018 at 18:41
  • @FábioDias in QGIS you can do both, either manually or programmatically using python (Inside QGIS as a plugin or as a standalone application). check this gis.stackexchange.com/questions/159699/…
    – Shiko
    May 1, 2018 at 20:41

2 Answers 2


Based on the post: https://www.gaia-gis.it/fossil/libspatialite/wiki?name=liblwgeom-4.0

SpatiaLite should support the ST_MakeValid argument. So this should work. Without your data it is hard to test. But it should work if you specify your geometry within the ST_MakeValid statement

So if you run:

ogr2ogr -f "ESRI Shapefile" valid_barangays.shp Barangays.shp -dialect sqlite -sql "select ST_MakeValid(geometry) as geometry, * from Barangays"

If that does not work, you will likely have to specify each other column instead of selecting *.

  • I tried query as suggested by you but I got error no such function: ST_MakeValid
    – AMahajan
    Aug 1, 2016 at 4:47
  • 1
    That means that your version of GDAL is compiled either without SpatiaLite at all or with so old SpatiaLite version that ST_MakeValid was not implemented yet.
    – user30184
    Aug 1, 2016 at 18:37

Using makevalid parameter could fix your problem:


Run the OGRGeometry::MakeValid() operation, followed by OGRGeometryFactory::removeLowerDimensionSubGeoms(), on geometries to ensure they are valid regarding the rules of the Simple Features specification.


ogr2ogr valid_barangays.shp Barangays.shp -makevalid

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.