point order in IGeometry and WKT

480 views
Skip to first unread message

Lenor

unread,
Oct 23, 2012, 1:23:45 AM10/23/12
to nettopol...@googlegroups.com

Hello everyone!
I'm using nts 1.12.1. My code looks like that:

public void DoSomething(Envelope extent)
{
 IGeometry extentGeom = _geomFactory.ToGeometry(extent);
 string wkt = extentGeom.AsText();
 SqlGeography sqlGeom = SqlGeography.STGeomFromText(new System.Data.SqlTypes.SqlChars(wkt), 4326); // (*)
}


and in the line (*) I'm getting an exception, because in wkt-string points are ordered in clockwise order, while SqlGeography, according to OGC standard, accepts counter clockwise order.
If I add a line like this:

extentGeom.Normalize();

it doesn't help either, points are still ordered clockwise.
With the nts v.1.7.3 that code works properly, points are ordered counter clockwise.
If I'm doing something wrong, please tell me how to make it work.
Thanks)

Felix Obermaier

unread,
Oct 23, 2012, 3:27:49 AM10/23/12
to nettopol...@googlegroups.com

Parsing from WKT is expensive. Have you tried the SqlGeographyReader/Writer classes?

 

Anyway, if the coordinate order is expected to be CCW you can do

if (!NetTopologySuite.Algorithms.CGAlgorithms.IsCCW(p.Coordinates))

    p = p.Reverse();

 

--
You received this message because you are subscribed to the Google Groups "NetTopologySuite" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nettopologysuite/-/3FzhBbDsqLQJ.
To post to this group, send email to nettopol...@googlegroups.com.
To unsubscribe from this group, send email to nettopologysui...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nettopologysuite?hl=en.

Lenor

unread,
Oct 23, 2012, 3:57:40 AM10/23/12
to nettopol...@googlegroups.com
Thanks for your attention)
 
1. It was just an example, for I wanted to see the wkt representation of my shape, so for now speed doesn't matter.
 
2. What I wanted to know, is: why from version 1.7.3 to 1.12.1 point order has changed.
 
I write the following simple code:

var envelope = new Envelope(1, 2, 1, 2);
var geom = geomFactory.ToGeometry(envelope);
var wkt = geom.AsText();

 
 
If I run it using NTS-1.7.3, I receive:
wkt = "POLYGON((1 1,2 1,2 2,1 2,1 1))"

This is counter clockwise order, and it's OGC-standard correct.
 
 
But if I'm using NTS-1.12.1, the string is different:
wkt = "POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))"

This is clockwise order, and according so OGC standard, it's incorrect.

 
In the 1.12.1, GeometryFactory.ToGeometry(Envelope envelope) method, points are adding in the clockwise order. Method Polygon.Normalize also is ordering points clockwise.

FObermaier

unread,
Oct 23, 2012, 4:25:26 AM10/23/12
to nettopol...@googlegroups.com
Where does it say in the OGC spec that polygon rings have to be counter-clockwise?
NTS behaves exactly like JTS does in this method.

Lenor

unread,
Oct 23, 2012, 6:23:10 AM10/23/12
to nettopol...@googlegroups.com
I may be wrong, but I've found it here:
6.1.11.1

The exterior boundary LinearRing defines the “top” of the surface which is the side of the surface from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. The interior LinearRings will have the opposite orientation, and appear as clockwise when viewed from the “top”

 
And can you please specify which version of nts behaves like jts - 1.7.3 or 1.12.1, since thay behave different?

FObermaier

unread,
Oct 23, 2012, 6:38:56 AM10/23/12
to nettopol...@googlegroups.com
I must have overread that.
NTS v1.12.1 behaves like JTS v1.12 in that matter.

John Diss

unread,
Oct 23, 2012, 6:41:23 AM10/23/12
to nettopol...@googlegroups.com

It is confused slightly by SFS for SQL  1.2.1 (http://www.opengeospatial.org/standards/sfs) stating that orientation has no bearing on validity as long as shells and holes are in opposite directions.

FObermaier

unread,
Oct 23, 2012, 7:37:15 AM10/23/12
to nettopol...@googlegroups.com
JTS used to return CCW polygons up to version 1.9. and started to return CW polygons at 1.10.


On Tuesday, October 23, 2012 12:23:10 PM UTC+2, Lenor wrote:

FObermaier

unread,
Oct 23, 2012, 3:06:16 PM10/23/12
to nettopol...@googlegroups.com

Lenor

unread,
Oct 23, 2012, 11:59:13 PM10/23/12
to nettopol...@googlegroups.com
I see. So, I'm supposed to reverse polygons myself, when I need it.
Thank you very much for your help.
Reply all
Reply to author
Forward
0 new messages