Exemple #1
0
        public static IGeometry InsertCurvePoint(IGeometry geometry, ICoordinate coordinate, int index)
        {
            var vertices = new List<ICoordinate>(geometry.Coordinates);
            vertices.Insert(index, coordinate);
            var geometryFactory = new GeometryFactory();

            if (geometry is ILineString)
            {
                return geometryFactory.CreateLineString(vertices.ToArray());
            }
            if (geometry is IPolygon)
            {
                return geometryFactory.CreatePolygon(geometryFactory.CreateLinearRing(vertices.ToArray()), null);
            }
            return geometry.Union(geometryFactory.CreatePoint(coordinate));
        }
Exemple #2
0
        public static IGeometry RemoveCurvePoint(IGeometry geometry, int index, bool keepLineStringEndPoints=false)
        {
            var vertices = new List<ICoordinate>(geometry.Coordinates);
            vertices.RemoveAt(index);
            var geometryFactory = new GeometryFactory();
            var lastIndex = geometry.Coordinates.Length - 1;
            if (geometry is ILineString)
            {
                if (vertices.Count < 2)
                {
                    return null;
                }
                if (keepLineStringEndPoints && (index == 0 || index == lastIndex))
                {
                    return null;
                }
                return geometryFactory.CreateLineString(vertices.ToArray());
            }
            if (geometry is IPolygon)
            {
                // If first or last index is removed -> remove corresponding duplicate at the other end and close the ring.
                if (index == lastIndex)
                {
                    vertices[0] = vertices[lastIndex];
                }
                if (index == 0)
                {
                    vertices[lastIndex - 1] = vertices[0];
                }

                if (vertices.Count < 4)
                {
                    return null;
                }
                return geometryFactory.CreatePolygon(geometryFactory.CreateLinearRing(vertices.ToArray()), null);
            }
            if (index < geometry.Coordinates.Length)
            {
                var coordinate = geometry.Coordinates[index];
                var point = geometryFactory.CreatePoint(coordinate);
                return geometry.Difference(point);
            }
            return geometry;
        }
 internal static LineString ToNTSLineString(Geometries.LineString lineString,
                                            GeometryFactory factory)
 {
     Coordinate[] coordinates = new Coordinate[lineString.NumPoints];
     int index = 0;
     foreach (Point point in lineString.Vertices)
         coordinates[index++] = ToNTSCoordinate(point, factory);
     return factory.CreateLineString(coordinates) as LineString;
 }