Is there a way to export a list of layers containing invalid geometry (e.g. self-intersections) via Python?

Our GIS server contains over 40,000 layers, some of which have all sorts of errors that simply cannot be identified manually.

Is there some sort of OGR/GDAL command that can perform this?

  • For layers that are in a dataset where gdal can do sql-queries you might be able to query a condition -sql "select * from filename WHERE not ST_IsValid(geometry)". Otherwise mass converting to sqlite or postgis and using the abilities of these formats might work. – pLumo Jan 27 '17 at 14:25
  • Please edit the question to specify the data format in question. – Vince Jan 28 '17 at 3:54

You may want to check out shapely library. You can loop ever the features and check the is_valid propery. This is from the docs:

object.is_valid Returns True if a feature is “valid” in the sense of 1.

A valid LinearRing may not cross itself or touch itself at a single point. A valid Polygon may not possess any overlapping exterior or interior rings. A valid MultiPolygon may not collect any overlapping polygons. Operations on invalid features may fail.

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.