Spatial4n.Core.Io.NtsShapeReadWriter.ReadShape C# (CSharp) Method

ReadShape() public method

public ReadShape ( String str ) : Shape
str String
return Shape
        public override Shape ReadShape(String str)
        {
            var shape = base.ReadStandardShape(str);
            if (shape == null)
            {
                try
                {
                    var reader = new WKTReader(((NtsSpatialContext)Ctx).GetGeometryFactory());
                    var geom = reader.Read(str);

                    //Normalize coordinates to geo boundary
                    CheckCoordinates(geom);

                    var ntsPoint = geom as NetTopologySuite.Geometries.Point;
                    if (ntsPoint != null)
                    {
                        return new NtsPoint(ntsPoint, Ctx);
                    }
                    else if (geom.IsRectangle)
                    {
                        bool crossesDateline = false;
                        if (Ctx.IsGeo())
                        {
                            //Polygon points are supposed to be counter-clockwise order. If JTS says it is clockwise, then
                            // it's actually a dateline crossing rectangle.
                            crossesDateline = !CGAlgorithms.IsCCW(geom.Coordinates);
                        }
                        Envelope env = geom.EnvelopeInternal;
                        if (crossesDateline)
                            return new RectangleImpl(env.MaxX, env.MinX, env.MinY, env.MaxY, Ctx);
                        else
                            return new RectangleImpl(env.MinX, env.MaxX, env.MinY, env.MaxY, Ctx);
                    }
                    return new NtsGeometry(geom, (NtsSpatialContext) Ctx, true);
                }
                catch (NetTopologySuite.IO.ParseException ex)
                {
                    throw new InvalidShapeException("error reading WKT", ex);
                }
            }
            return shape;
        }