The data I've loaded from a shapefile into a geometry column in SQL Server (using NetTopologySuite) is not producing valid GeoJSON when I export it because it doesn't follow the right-hand rule.
I thought this would be easy to fix with the
MakeValid() function, but it's not correcting the issue.
I tried with a simplified geometry as below:
declare @geom geometry select @geom = geometry::STGeomFromText('POLYGON (( 0 0, 0 1, 2 1, 2 0, 0 0 ))', 4326) select @geom, @geom.IsValidDetailed()
SQL Server says it's valid (24400: Valid), so presumably that's why it's not fixing it in the
What's the best way to resolve this? I've seen an option to use:
UPDATE table SET geom = geom.STUnion(geom.STStartPoint()) which works for simple polygons, but I'm not sure how well it will work for more complex geometries.