Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert empty polygon to geography column #588

Closed
4 tasks done
palhal opened this issue Feb 2, 2022 · 2 comments
Closed
4 tasks done

How to insert empty polygon to geography column #588

palhal opened this issue Feb 2, 2022 · 2 comments

Comments

@palhal
Copy link

palhal commented Feb 2, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of NetTopologySuite
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

Before inserting a polygon into a geography column, NTS checks that IsCCW is true. I want to insert an empty polygon, but haven't found a way to create one with IsCCW set to true. Perhaps NTS should not check the orientation for empty geometries? I am able to insert an empty polygon using raw SQL.

Steps to Reproduce

Approach 1:

var factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var ring = factory.CreateLinearRing();

if (!ring.IsCCW)
{
    ring = (LinearRing)((Geometry)ring).Reverse();
}

var polygon = factory.CreatePolygon(ring);
Console.WriteLine(ring.IsCCW); // False
Console.WriteLine(polygon.Shell.IsCCW); // False

Approach 2:

var factory = new GeometryFactoryEx(new PrecisionModel(), srid: 4326)
{
    OrientationOfExteriorRing = LinearRingOrientation.CounterClockwise
};

var polygon = factory.CreatePolygon();
Console.WriteLine(polygon.Shell.IsCCW); // False

Needless to say, both approaches result in the same error:
System.ArgumentException : When writing a SQL Server geography value, the shell of a polygon must be oriented counter-clockwise.

System Configuration

Tell us about the environment where you are experiencing the bug:

  • NetTopologySuite version: 2.3.0
  • Other NetTopologySuite packages and versions: Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite 6.0.1
  • Environment (Operating system, version and so on): Windows 10, MS SQL 15
  • .NET version: 6.0
@FObermaier
Copy link
Member

This is a duplicate of NetTopologySuite/NetTopologySuite.IO.SqlServerBytes#14

@palhal
Copy link
Author

palhal commented Feb 2, 2022

Oh, I'm sorry. I'm not too familiar with NTS and its modules yet. I couldn't find that issue by googling either. Feel free to close this.

@DGuidi DGuidi closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants