Example #1
0
        protected virtual IRectangle MakeRectFromPoly(IGeometry geometry)
        {
            Debug.Assert(geometry.IsRectangle);
            Envelope env             = geometry.EnvelopeInternal;
            bool     crossesDateline = false;

            if (m_ctx.IsGeo && m_datelineRule != Nts.DatelineRule.None)
            {
                if (m_datelineRule == Nts.DatelineRule.CcwRect)
                {
                    // If NTS says it is clockwise, then it's actually a dateline crossing rectangle.
#pragma warning disable 612, 618
                    crossesDateline = !CGAlgorithms.IsCCW(geometry.Coordinates);
#pragma warning restore 612, 618
                }
                else
                {
                    crossesDateline = env.Width > 180;
                }
            }
            if (crossesDateline)
            {
                return(m_ctx.MakeRectangle(env.MaxX, env.MinX, env.MinY, env.MaxY));
            }
            else
            {
                return(m_ctx.MakeRectangle(env.MinX, env.MaxX, env.MinY, env.MaxY));
            }
        }
Example #2
0
        public virtual void PolyToRectCcwRule()
        {
            NtsSpatialContext ctx = (NtsSpatialContext) new NtsSpatialContextFactory()
            {
                datelineRule = DatelineRule.CcwRect
            }.NewSpatialContext();

            //counter-clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 0, -170 0, -170 10, 160 10, 160 0))"),
                         ctx.MakeRectangle(160, -170, 0, 10));
            //clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 10, -170 10, -170 0, 160 0, 160 10))"),
                         ctx.MakeRectangle(-170, 160, 0, 10));
        }
Example #3
0
 public virtual void TestPolyToRect()
 {
     //poly is a rect (no dateline issue)
     AssertParses("POLYGON((0 5, 10 5, 10 20, 0 20, 0 5))", ctx.MakeRectangle(0, 10, 5, 20));
 }