2

Presently, I have a snippet of code that works well when iterating over a file geodatabase. The problem I'm currently having is that, on occasion, a geometry is supplied that is invalid, such as a stacked point at the end of a line segment that, when GetNextFeature is called, causes an exception of an "Invalid curve". After digging into the documentation, it appears that the geometry always returns with the query. Despite me not including it in the SELECT statement and even when I attempt to apply a field filter on the geometry field, the error continues to persist.

Is there a better way to filter these errors?

I attempted to use the "SQLite" dialect with a call of ST_IsValid in the WHERE clause to only pull the valid items, but that still didn't work. My assumption there is that they may be "Sqlite Valid", but not GDAL/OGR valid. Any guidance?

using (var fgdbDriver = Ogr.GetDriverByName("OpenFileGDB"))
    using (var ds = fgdbDriver.Open(path, 0))
    {
       var sql = $"SELECT {field} FROM {layerName}";
       var execResult = ds.ExecuteSQL(sql, null, "");
       while ((feature = execResult.GetNextFeature()) != null)
       {
           //do work
       }
    }
4
  • Does SQLite dialect work for you generally? What does select spatialite_version() return?
    – user30184
    Jan 14 at 19:43
  • We had never used the dialect previously, but I started to look for ways to filter "really bad" shapes from the select statement, so I attempted to see if that would work but to no avail. Executing the above query yielded: 4.3.0-RC1
    – JJMar
    Jan 14 at 20:21
  • That version does already have functions ST_IsValid and ST_MakeValid gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html.
    – user30184
    Jan 14 at 21:42
  • Right, but even if I exclude the ones that are false for ST_IsValid, the loop still blows up on the invalid geometries wnen GetNextFeature is called. My adjusted query was: "SELECT {field} FROM {layerName} WHERE ST_IsValid(Shape) = 1"
    – JJMar
    Jan 17 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.