4

I previously asked this question@ regarding finding files that contain an invalid geometry using OGR.

The following SQL command was suggested to me, which seemed to work a treat: -sql "select * from filename WHERE not ST_IsValid(geometry)"

I am now trying to get this to work under python using the following code:

from osgeo import ogr
driver = ogr.GetDriverByName('MapInfo File') 
dataSource = driver.Open(file, 0)
layer = dataSource.GetLayer() 
result = dataSource.ExecuteSQL("select * from file WHERE ST_IsValid(geometry)")
featureCount = result.GetFeatureCount() 
print (featureCount)

Upon running the code however, I get the following error message: ERROR 1: Undefined function 'ST_IsValid' used.

Does anyone know how I go about checking ST_IsValid under python?

asked Feb 7, 2017 at 13:43
1

1 Answer 1

4

I don't think the plain vanilla OGR SQL includes spatial functions? You can specify pszDialect in the parameters for ExecuteSQL, for example to use SQLITE's spatial functions. http://www.gdal.org/ogr_sql_sqlite.html

answered Feb 7, 2017 at 15:04
1
  • Excellent, using 'dataSource.ExecuteSQL("select * from HousingOptions WHERE ST_IsValid(geometry)", dialect = "SQLITE")' seems to have done the trick. I am getting some kind of logical output now. Thank you! Commented Feb 7, 2017 at 15:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.