Set SkipGeographyChecks to true

entity-framework-core geometry polygon

Question

Hi I get this exception when saving multiple polygons. How can I set SkipGeographyChecks to true ?

Exception:

When writing a SQL Server geography value, the shell of a polygon must be oriented counter-clockwise. To write polygons without a shell, set SkipGeographyChecks

Code sample :

var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var poly = new Polygon[] {
new Polygon(new LinearRing(new Coordinate[]
{
        new Coordinate(19.2385498607974, -51.50390625,0),
        new Coordinate(24.1367281697474, -37.6171875,0),
        new Coordinate(13.8487471475372, -18.10546875,0),
        new Coordinate(19.2385498607974, -51.50390625,0),
                    })),
new Polygon(new LinearRing(new Coordinate[]
{
        new Coordinate(-10.0445849842118, -53.0859375,0),
        new Coordinate(4.13824308398371, -58.7109375,0),
        new Coordinate(2.20770545570541, -68.73046875,0),
        new Coordinate(-8.83079518432893, -79.1015625,0),
        new Coordinate(-17.3820949478775, -81.2109375,0),
        new Coordinate(-21.0332372344673, -51.328125,0),
        new Coordinate(-10.0445849842118, -53.0859375,0),
})) 
};

var currentLocation = geometryFactory.CreateMultiPolygon(poly) as MultiPolygon;
dbset.Polygons = currentLocation;
_context.Add(dbset);
await _context.SaveChangesAsync();
1
0
1/30/2019 11:41:57 AM

Popular Answer

As far as I can tell, SkipGeographyChecks was removed as a property before the reference to it was removed from this error - Github issue for removing the reference to this property.

I also found that this error may arise if the points of your polygon are ordered in the wrong direction. The convention is that the direction of the points what the "inside" of the polygon is - ie: if points for a polygon are counterclockwise, the area of that polygon is inside the boundary, but if the points are clockwise then the area is the entire world except for inside that boundary (because the points are essentially counterclockwise around everything outside of the boundary). You can determine if this is your issue by checking the IPolygon.Shell.IsCCW property. If this is your issue, you can solve it by using the IPolygon.Shell.Reverse() method. See this GIS StackExchange question (where I found this information) for some actual code you can use.

1
10/22/2019 2:20:51 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow