public static void main(string[] args)
		{
			ExtendedCoordinateSequenceFactory seqFact = ExtendedCoordinateSequenceFactory.Instance();
			
			ExtendedCoordinate[] array1 = new ExtendedCoordinate[] { new ExtendedCoordinate(0, 0, 0, 91), 
                new ExtendedCoordinate(10, 0, 0, 92), new ExtendedCoordinate(10, 10, 0, 93), 
                new ExtendedCoordinate(0, 10, 0, 94), new ExtendedCoordinate(0, 0, 0, 91)};
			ICoordinateSequence seq1 = seqFact.Create(array1);
			
			ICoordinateSequence seq2 = seqFact.Create(new ExtendedCoordinate[] { new ExtendedCoordinate(5, 5, 0, 91), 
                new ExtendedCoordinate(15, 5, 0, 92), new ExtendedCoordinate(15, 15, 0, 93), 
                new ExtendedCoordinate(5, 15, 0, 94), new ExtendedCoordinate(5, 5, 0, 91)});
			
			GeometryFactory fact = new GeometryFactory(ExtendedCoordinateSequenceFactory.Instance());

            IGeometry g1 = fact.CreatePolygon(fact.CreateLinearRing(seq1), null);
            IGeometry g2 = fact.CreatePolygon(fact.CreateLinearRing(seq2), null);
			
			Console.WriteLine("WKT for g1: " + g1);
			Console.WriteLine("Internal rep for g1: " + ((IPolygon) g1).ExteriorRing.CoordinateSequence);
			
			Console.WriteLine("WKT for g2: " + g2);
            Console.WriteLine("Internal rep for g2: " + ((IPolygon)g2).ExteriorRing.CoordinateSequence);

            IGeometry gInt = g1.Intersection(g2);
			
			Console.WriteLine("WKT for gInt: " + gInt);
            Console.WriteLine("Internal rep for gInt: " + ((IPolygon)gInt).ExteriorRing.CoordinateSequence);
		}
Ejemplo n.º 2
0
		private List<IPolygon> tessellator(int cellWidth, int cellHeight, int numRows, int numColumns)
		{
			try {
				GeometryFactory f = new GeometryFactory();
				List<IPolygon> grid = new List<IPolygon>();
				double x = _origin.X;// pol.Coordinates[0].X;
				double y = _origin.Y;//pol.Coordinates[0].Y;
				for (int i = 1; i <= numColumns; i++)
				{
					for (int j = 1; j <= numRows; j++)
					{
						Coordinate[] coords;

						coords = new Coordinate[] {
							new Coordinate(x, y),
							new Coordinate(x + cellWidth, y),
							new Coordinate(x + cellWidth, y + cellHeight),
							new Coordinate(x, y+cellHeight),
							new Coordinate(x, y)};
						
						LinearRing ring  = (LinearRing) f.CreateLinearRing(coords);
						
						IPolygon newpol=(IPolygon) f.CreatePolygon(ring, null);
						newpol.UserData=i+" - "+j;
						grid.Add(newpol);
						y += cellHeight;
					}
					if(i!=0)
					{
						x += cellWidth;
					}
					y = _origin.Y;
				}
				return grid;
			} catch (Exception ex) {
				throw ex;
			}
			
			
		}
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
 internal static Polygon ToNTSPolygon(Geometries.Polygon polygon,
                                      GeometryFactory factory)
 {
     LinearRing shell = ToNTSLinearRing(polygon.ExteriorRing, factory);
     LinearRing[] holes = new LinearRing[polygon.InteriorRings.Count];
     int index = 0;
     foreach (Geometries.LinearRing hole in polygon.InteriorRings)
         holes[index++] = ToNTSLinearRing(hole, factory);
     return factory.CreatePolygon(shell, holes) as Polygon;
 }