Exemple #1
0
        public void TestLineLine1()
        {
            // test when the point being tested in a node on the line
            Coordinate coordLine1 = new Coordinate(5.0,5.0);
            Coordinate coordLine2 = new Coordinate(10.0,10.0);
            Coordinate coordLine3 = new Coordinate(5.0, 10.0);
            Coordinate coordLine4 = new Coordinate(10.0,5.0);

            Coordinates coordinates1 = new Coordinates();
            coordinates1.Add(coordLine1);
            coordinates1.Add(coordLine2);

            Coordinates coordinates2 = new Coordinates();
            coordinates2.Add(coordLine3);
            coordinates2.Add(coordLine4);

            LineString linestring1 = _factory.CreateLineString(coordinates1);
            LineString linestring2 = _factory.CreateLineString(coordinates2);

            Geometry pt =  linestring1.Intersection(linestring2);

            Assertion.AssertEquals("intersects",true,linestring1.Intersects(linestring2));
            Assertion.AssertEquals("disjoint",false,linestring1.Disjoint(linestring2));
            Assertion.AssertEquals("contains",false,linestring1.Contains(linestring2));
            Assertion.AssertEquals("within",false,linestring1.Within(linestring2));

            Assertion.AssertEquals("crosses",true,linestring1.Crosses(linestring2));

            Assertion.AssertEquals("touches",false,linestring1.Touches(linestring2));

            // always returns false when a point is involved
            Assertion.AssertEquals("overlaps",false,linestring1.Overlaps(linestring2));
        }
Exemple #2
0
		public void TestPointLine2()
		{
			// test when the point being tested in a node on the line	
			Coordinate coordLine1 = new Coordinate(5.0,5.0);
			Coordinate coordLine2 = new Coordinate(10.0,10.0);
			Coordinate coordPoint1 = new Coordinate(6.0,6.0);

			Coordinates coordinates = new Coordinates();
			coordinates.Add(coordLine1);
			coordinates.Add(coordLine2);

			Point point1 = _factory.CreatePoint(coordPoint1);

			LineString linestring = _factory.CreateLineString(coordinates);
			Assertion.AssertEquals("intersects",true,point1.Intersects(linestring)); 
			Assertion.AssertEquals("intersects",true,linestring.Intersects(point1)); 
			Assertion.AssertEquals("disjoint",false,point1.Disjoint(linestring)); 
			Assertion.AssertEquals("contains",false,point1.Contains(linestring));
			Assertion.AssertEquals("OppositeContains", true, linestring.Contains( point1 ));
			Assertion.AssertEquals("within",true,point1.Within(linestring));		// point1 is within linestring and linestring contains point.

			// always returns false when a point is involves
			Assertion.AssertEquals("crosses",false,point1.Crosses(linestring));

			Assertion.AssertEquals("touches",false,point1.Touches(linestring));		// false because point is in the interior of linestring and not the boundary. The boundary is the endpoints.
			
			// always returns false when a point is involved
			Assertion.AssertEquals("overlaps",false,point1.Overlaps(linestring));

		}
Exemple #3
0
		public void TestPointLine1()
		{
			// test when the point being tested in a node on the line	
			Coordinate coordLine1 = new Coordinate(5.0,5.0);
			Coordinate coordLine2 = new Coordinate(10.0,10.0);
			Coordinate coordPoint1 = new Coordinate(5.0,5.0);

			Coordinates coordinates = new Coordinates();
			coordinates.Add(coordLine1);
			coordinates.Add(coordLine2);

			Point point1 = _factory.CreatePoint(coordPoint1);

			LineString linestring = _factory.CreateLineString(coordinates);
			Assertion.AssertEquals("intersects",true,point1.Intersects(linestring));
			Assertion.AssertEquals("disjoint",false,point1.Disjoint(linestring));
			Assertion.AssertEquals("contains",false,point1.Contains(linestring));
			Assertion.AssertEquals("within",false,point1.Within(linestring));

			// always returns false when a point is involves
			Assertion.AssertEquals("crosses",false,point1.Crosses(linestring));

			Assertion.AssertEquals("touches",true,point1.Touches(linestring));
			
			// always returns false when a point is involved
			Assertion.AssertEquals("overlaps",false,point1.Overlaps(linestring));
		}
		private MultiPolygon CreateMP1()
		{
			Polygon[] polygons = new Polygon[2];
			LineString[] rings = new LineString[2];

			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(5, 1);
			coords.Add(coord);
			coord = new Coordinate(6, 2);
			coords.Add(coord);
			coord = new Coordinate(7, 3);
			coords.Add(coord);
			coord = new Coordinate(6, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 2);
			coords.Add(coord);
			coord = new Coordinate(5, 1);
			coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            LinearRing exterior1 = gf.CreateLinearRing(coords);
			polygons[0] = gf.CreatePolygon(exterior1);
			rings[0] = exterior1 as LineString;

			coords = new Coordinates();
			coord = new Coordinate(5, 1);
			coords.Add(coord);
			coord = new Coordinate(6, 2);
			coords.Add(coord);
			coord = new Coordinate(7, 3);
			coords.Add(coord);
			coord = new Coordinate(6, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 2);
			coords.Add(coord);
			coord = new Coordinate(5, 1);
			coords.Add(coord);

			LinearRing exterior2 = gf.CreateLinearRing(coords);
			polygons[1] = gf.CreatePolygon(exterior2);
			rings[1] = exterior2;

			_mls1 = gf.CreateMultiLineString(rings);

			return gf.CreateMultiPolygon(polygons);
		}
		public void TestLineString1()
		{
			Coordinates coordinates = new Coordinates();
			coordinates.Add( new Coordinate(1,2) );
			coordinates.Add( new Coordinate(1.2,2.3) );
			LineString linestring = _factory.CreateLineString( coordinates );
			string wkt = _writer.WriteFormatted(linestring);
			Assertion.AssertEquals("multi point","LINESTRING (1 2, 1.2 2.3)",wkt);
		}
		public void TestMultiPoint1()
		{
			Coordinates coordinates = new Coordinates();
			coordinates.Add( new Coordinate(1,2) );
			coordinates.Add( new Coordinate(1.2,2.3) );
			MultiPoint multipoint = _factory.CreateMultiPoint( coordinates );
			string wkt = _writer.WriteFormatted(multipoint);
			Assertion.AssertEquals("multi point","MULTIPOINT (1 2, 1.2 2.3)",wkt);
		}
		private Polygon Poly1()
		{
			_coords1 = new Coordinates();
			Coordinate coord = new Coordinate(5, 1);
			_coords1.Add(coord);
			coord = new Coordinate(6, 2);
			_coords1.Add(coord);
			coord = new Coordinate(7, 3);
			_coords1.Add(coord);
			coord = new Coordinate(6, 4);
			_coords1.Add(coord);
			coord = new Coordinate(5, 5);
			_coords1.Add(coord);
			coord = new Coordinate(4, 4);
			_coords1.Add(coord);
			coord = new Coordinate(3, 3);
			_coords1.Add(coord);
			coord = new Coordinate(4, 2);
			_coords1.Add(coord);
			coord = new Coordinate(5, 1);
			_coords1.Add(coord);

			_gf = new GeometryFactory(_precMod, _sRID);
			_exterior1 = _gf.CreateLinearRing(_coords1);
			Polygon polygon = _gf.CreatePolygon(_exterior1);

			return polygon;
		}
Exemple #8
0
        ///<summary>
        /// Converts a linearring to be sure it is clockwise.
        ///</summary>
        ///<remarks>Normal form is a unique representation
        /// for Geometry's. It can be used to test whether two Geometrys are equal in a way that is
        /// independent of the ordering of the coordinates within them. Normal form equality is a stronger
        /// condition than topological equality, but weaker than pointwise equality. The definitions for
        /// normal form use the standard lexicographical ordering for coordinates. Sorted in order of
        /// coordinates means the obvious extension of this ordering to sequences of coordinates.
        ///</remarks>
        private void Normalize(LinearRing ring, bool clockwise)
        {
            if (ring.IsEmpty())
            {
                return;
            }
            Coordinates uniqueCoordinates = new Coordinates();

            for (int i = 0; i < ring.GetNumPoints() - 1; i++)
            {
                uniqueCoordinates.Add(ring.GetCoordinateN(i));                                  // copy all but last one into uniquecoordinates
            }
            Coordinate minCoordinate = MinCoordinate(ring.GetCoordinates());

            Scroll(uniqueCoordinates, minCoordinate);
            Coordinates ringCoordinates = ring.GetCoordinates();

            ringCoordinates.Clear();
            ringCoordinates.AddRange(uniqueCoordinates);
            ringCoordinates.Add(uniqueCoordinates[0].Clone());                          // add back in the closing point.
            if (_cgAlgorithms.IsCCW(ringCoordinates) == clockwise)
            {
                ReversePointOrder(ringCoordinates);
            }
        }
Exemple #9
0
        /// <summary>
        /// If the coordinate array has repeated points, constructs new array
        /// containing no repeated points.
        /// </summary>
        /// <param name="coord">The set of coordinates to be examined.</param>
        /// <returns>A new set of coordinates with no repeating points.</returns>
        public static Coordinates RemoveRepeatedPoints(Coordinates coord)
        {
            if (!HasRepeatedPoints(coord))
            {
                return(coord);
            }
            Coordinates newCoords = new Coordinates();

            newCoords.Add(coord[0]);                            // add the first coordinate
            for (int i = 1; i < coord.Count; i++)
            {
                if (!coord[i - 1].Equals(coord[i]))                             // if this coord does not equal the last coords, add otherwise skip.
                {
                    newCoords.Add(coord[i], false);
                }
            }
            return(newCoords);
        }
Exemple #10
0
        /// <summary>
        /// Reverses the order of the coordinates in this set of coordinates.
        /// </summary>
        /// <returns>The set of coordinates with the corder of the coordinates reversed.</returns>
        public Coordinates ReverseCoordinateOrder()
        {
            Coordinates coordinates = new Coordinates();

            for (int i = 0; i < base.Count; i++)
            {
                coordinates.Add(base[base.Count - 1 - i]);
            }
            return(coordinates);
        }
Exemple #11
0
		/// <summary>
		/// Returns this Geometry's external vertices (points).
		/// </summary>
		/// <remarks>These point are based on the output of precisionModel.ToExternal.</remarks>
		/// <returns>Returns the external vertices of this Geometry.</returns>
		public virtual Coordinates GetCoordinatesInternal()
		{
			Coordinates externalCoordinates = new Coordinates();
			Coordinates internalCoordinates = GetCoordinates();
			for ( int i=0; i < internalCoordinates.Count; i++ )
			{
				externalCoordinates.Add( _precisionModel.ToExternal( internalCoordinates[i] ) );			// creates a new Coordinate() in the process.
			}
			return externalCoordinates;
		} //public virtual Coordinates GetCoordinatesInternal()
Exemple #12
0
        /// <summary>
        /// Creates an exact replica of this set of coordinates.
        /// </summary>
        /// <returns>A new set of coordinates containing the same coordinates as the original.</returns>
        public new Coordinates Clone()
        {
            Coordinates coords = new Coordinates();

            foreach (Coordinate coord in this)
            {
                coords.Add(coord);
            }
            return(coords);
        }
		/// <summary>
		/// Returns the unique Coordinates.
		/// </summary>
		/// <returns>Return the Coordinates collected by this CoordinateArrayFilter.</returns>
		public Coordinates GetCoordinates() 
		{
			// copy costruct a new list of coordinates.
			Coordinates coordinates = new Coordinates();
			foreach(object obj in _treeSet)
			{
				coordinates.Add(obj);
			}
			return coordinates;
		}
Exemple #14
0
        /// <summary>
        /// Converts an envnelope to a geometry.
        /// </summary>
        /// <param name="envelope">The Envelope to convert to a Geometry.</param>
        /// <param name="precisionModel">The specification of the grid of allowable points for the new Geometry.</param>
        /// <param name="SRID">The ID of the Spatial Reference System used by the Envelope.</param>
        /// <returns>an empty Point (for null Envelopes), a Point (when min x = max x and min y = max y)
        /// or a Polygon (in all other cases)</returns>
        /// <exception cref="TopologyException"> if coordinates is not a closed linestring, that is, if the
        /// first and last coordinates are not equal.</exception>
        public static Geometry ToGeometry(Envelope envelope, PrecisionModel precisionModel, int SRID)
        {
            if (envelope.IsNull())
            {
                return(new Point(null, precisionModel, SRID));
            }
            if (envelope.MinX == envelope.MaxX && envelope.MinY == envelope.MaxY)
            {
                return(new Point(new Coordinate(envelope.MinX, envelope.MinY), precisionModel, SRID));
            }
            Coordinates coords = new Coordinates();

            coords.Add(new Coordinate(envelope.MinX, envelope.MinY));
            coords.Add(new Coordinate(envelope.MaxX, envelope.MinY));
            coords.Add(new Coordinate(envelope.MaxX, envelope.MaxY));
            coords.Add(new Coordinate(envelope.MinX, envelope.MaxY));
            coords.Add(new Coordinate(envelope.MinX, envelope.MinY));
            return(new Polygon(new LinearRing(coords, precisionModel, SRID), precisionModel, SRID));
        }
Exemple #15
0
        ///<summary>
        ///  Returns this Geometry's vertices.
        ///</summary>
        ///<remarks>Do not modify the array, as it may be the actual array stored
        ///  by this Geometry.  The Geometries contained by composite Geometries must be Geometry's;
        ///  that is, they must implement get Coordinates.</remarks>
        ///<returns>Returns the vertices of this Geometry</returns>
        public override Coordinates GetCoordinates()
        {
            // point does not have a coordinates list so will need to create one and add the coordinate.
            Coordinates pointCoord = new Coordinates();

            if (!IsEmpty())
            {
                pointCoord.Add(_coordinate);
            }
            return(pointCoord);
        }
Exemple #16
0
        ///<summary>
        ///  Returns the boundary, or the empty geometry if this Geometry is empty.
        ///</summary>
        ///<remarks>For a discussion
        ///  of this function, see the OpenGIS Simple Features Specification. As stated in SFS
        ///  Section 2.1.13.1, "the boundary  of a Geometry is a set of Geometries of the next lower dimension."</remarks>
        ///<returns>Returns the closure of the combinatorial boundary of this Geometry.</returns>
        public override Geometry GetBoundary()
        {
            if (IsEmpty())
            {
                return(_geometryFactory.CreateGeometryCollection(null));
            }

            if (this.IsClosed())
            {
                //if the LineString is closed return an empty multipoint
                return(_geometryFactory.CreateMultiPoint(new Coordinates()));
            }
            Coordinates coords = new Coordinates();
            Coordinate  coord  = new Coordinate(this.GetStartPoint().X, this.GetStartPoint().Y);

            coords.Add(coord);
            coord = new Coordinate(this.GetEndPoint().X, this.GetEndPoint().Y);
            coords.Add(coord);
            return(_geometryFactory.CreateMultiPoint(coords));
        }
        ///<summary>
        ///  Returns this Geometry's vertices.
        ///</summary>
        ///<remarks>Do not modify the array, as it may be the actual array stored
        ///  by this Geometry.  The Geometries contained by composite Geometries must be Geometry's;
        ///  that is, they must implement get Coordinates.  </remarks>
        ///<returns>Returns the vertices of this Geometry</returns>
        public override Coordinates GetCoordinates()
        {
            Coordinates coordinates = new Coordinates();

            if (_geometries != null)
            {
                foreach (Geometry geom in _geometries)
                {
                    Coordinates childCoords = geom.GetCoordinates();
                    foreach (Coordinate coord in childCoords)
                    {
                        coordinates.Add(coord);
                    }
                }
            }
            return(coordinates);
        }
Exemple #18
0
        /// <summary>
        /// Projects a geometry using the given transformation.
        /// </summary>
        /// <param name="coordinateTransform">The transformation to use.</param>
        /// <returns>A projected line string object.</returns>
        public override Geometry Project(ICoordinateTransformation coordinateTransform)
        {
            if (coordinateTransform == null)
            {
                throw new ArgumentNullException("coordinateTransform");
            }
            if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection))
            {
                throw new ArgumentException("coordinateTransform must be a MapProjection.");
            }

            int           sourceSRID = int.Parse(coordinateTransform.SourceCS.AuthorityCode);
            int           targetSRID = int.Parse(coordinateTransform.TargetCS.AuthorityCode);
            MapProjection projection = (MapProjection)coordinateTransform.MathTransform;
            int           newSRID    = GetNewSRID(coordinateTransform);

            Coordinates projectedCoordinates = new Coordinates();
            double      x = 0.0;
            double      y = 0.0;
            Coordinate  projectedCoordinate;
            Coordinate  external;
            Coordinate  coordinate;

            for (int i = 0; i < _points.Count; i++)
            {
                coordinate = _points[i];
                external   = _geometryFactory.PrecisionModel.ToExternal(coordinate);
                if (this._SRID == sourceSRID)
                {
                    projection.MetersToDegrees(external.X, external.Y, out x, out y);
                }
                else if (this._SRID == targetSRID)
                {
                    projection.DegreesToMeters(external.X, external.Y, out x, out y);
                }
                projectedCoordinate = _geometryFactory.PrecisionModel.ToInternal(new Coordinate(x, y));
                projectedCoordinates.Add(projectedCoordinate);
            }
            return(new LineString(projectedCoordinates, this.PrecisionModel, newSRID));
        }
Exemple #19
0
        private MultiLineString CreateMLS1()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[10];
            int c = 0;
            for(int i = 10; i > 0; i--)
            {
                for(int j = i; j < i+10; j++)
                {
                    coord = new Coordinate();
                    coord.X = (double)j;
                    coord.Y = (double)j+5;
                    coords.Add(coord);
                }
                lineString = gf.CreateLineString(coords);
                ls[c] = lineString;
                c++;
            }
            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
		private MultiPolygon CreateMP2()
		{
			Polygon[] polygons = new Polygon[2];

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(10, 13);
			coords.Add(coord);
			coord = new Coordinate(11, 13);
			coords.Add(coord);
			coord = new Coordinate(12, 13);
			coords.Add(coord);
			coord = new Coordinate(13, 14);
			coords.Add(coord);
			coord = new Coordinate(14, 15);
			coords.Add(coord);
			coord = new Coordinate(15, 16);
			coords.Add(coord);
			coord = new Coordinate(15, 17);
			coords.Add(coord);
			coord = new Coordinate(15, 18);
			coords.Add(coord);
			coord = new Coordinate(14, 19);
			coords.Add(coord);
			coord = new Coordinate(13, 20);
			coords.Add(coord);
			coord = new Coordinate(12, 21);
			coords.Add(coord);
			coord = new Coordinate(11, 21);
			coords.Add(coord);
			coord = new Coordinate(10, 21);
			coords.Add(coord);
			coord = new Coordinate(9, 20);
			coords.Add(coord);
			coord = new Coordinate(8, 19);
			coords.Add(coord);
			coord = new Coordinate(7, 18);
			coords.Add(coord);
			coord = new Coordinate(7, 17);
			coords.Add(coord);
			coord = new Coordinate(7, 16);
			coords.Add(coord);
			coord = new Coordinate(8, 15);
			coords.Add(coord);
			coord = new Coordinate(9, 14);
			coords.Add(coord);
			coord = new Coordinate(10, 13);
			coords.Add(coord);

			LinearRing exterior = gf.CreateLinearRing(coords);

			coords = new Coordinates();
			coord = new Coordinate(10, 16);
			coords.Add(coord);
			coord = new Coordinate(11, 17);
			coords.Add(coord);
			coord = new Coordinate(10, 18);
			coords.Add(coord);
			coord = new Coordinate(9, 17);
			coords.Add(coord);
			coord = new Coordinate(10, 16);
			coords.Add(coord);

			LinearRing interior = gf.CreateLinearRing(coords);
			LinearRing[] linearRings = new LinearRing[1];
			linearRings[0] = interior;

			polygons[0] = gf.CreatePolygon(exterior, linearRings);

			coords = new Coordinates();
			coord = new Coordinate(5, 1);
			coords.Add(coord);
			coord = new Coordinate(6, 2);
			coords.Add(coord);
			coord = new Coordinate(7, 3);
			coords.Add(coord);
			coord = new Coordinate(6, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 2);
			coords.Add(coord);
			coord = new Coordinate(5, 1);
			coords.Add(coord);

			exterior = gf.CreateLinearRing(coords);
			polygons[1] = gf.CreatePolygon(exterior);

			return gf.CreateMultiPolygon(polygons);
		}
		/// <summary>
		/// Method to create a Simple NonClosed Linestring for testing purposes
		/// </summary>
		/// <returns>A lineString</returns>
		private LineString SimpleOpen()
		{
			_coords = new Coordinates();
			Coordinate coord = new Coordinate(0.0,0.0);
			for(int i = 1; i < 12; i++)
			{
				coord = new Coordinate((double)i, (double)i);
				_coords.Add(coord);
			}
			coord = new Coordinate(11, 12);
			_coords.Add(coord);
			coord = new Coordinate(10, 13);
			_coords.Add(coord);
			coord = new Coordinate(9, 14);
			_coords.Add(coord);
			coord = new Coordinate(8, 15);
			_coords.Add(coord);
			coord = new Coordinate(9, 16);
			_coords.Add(coord);
			coord = new Coordinate(10, 17);
			_coords.Add(coord);
			coord = new Coordinate(11, 18);
			_coords.Add(coord);
			coord = new Coordinate(12, 19);
			_coords.Add(coord);
			coord = new Coordinate(11, 20);
			_coords.Add(coord);
			coord = new Coordinate(10, 21);
			_coords.Add(coord);
			coord = new Coordinate(9, 22);
			_coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
			LineString ls = gf.CreateLineString(_coords);
			return ls;
		}
		public void test_ToString()
		{
			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(1.0, 2.0);
			coords.Add(coord);
			coord = new Coordinate(3.0, 4.0);
			coords.Add(coord);
			
			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
			LineString ls1 = gf.CreateLineString(coords);
			Assertion.AssertEquals("ToString-1: ", "LineString:(1, 2, NaN),(3, 4, NaN)", ls1.ToString());

			coord = new Coordinate(2.4, 4.9);
			coords.Add(coord);
			LineString ls2 = gf.CreateLineString(coords);
			Assertion.AssertEquals("ToString-2: ", "LineString:(1, 2, NaN),(3, 4, NaN),(2.4, 4.9, NaN)", ls2.ToString());

			coord = new Coordinate(1.0, 1.0);
			coords.Add(coord);
			LineString ls3 = gf.CreateLineString(coords);
			Assertion.AssertEquals("ToString-3: ", "LineString:(1, 2, NaN),(3, 4, NaN),(2.4, 4.9, NaN),(1, 1, NaN)", ls3.ToString());
		}
		private LineString ThrowsException()
		{
			Coordinates coords = new Coordinates();

			Coordinate coord = new Coordinate(1,1);
			coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
			LineString ls = gf.CreateLineString(coords);

			return ls;
		}
		/// <summary>
		/// Method to create a Simple Closed Linestring for testing purposes
		/// </summary>
		/// <returns>A lineString</returns>
		private LineString SimpleClosed()
		{
			Coordinates coords = new Coordinates();
			Coordinate coord ;//Coordinate(0, 0);

			coord = new Coordinate(10, 13);
			coords.Add(coord);
			coord = new Coordinate(11, 13);
			coords.Add(coord);
			coord = new Coordinate(12, 13);
			coords.Add(coord);
			coord = new Coordinate(13, 14);
			coords.Add(coord);
			coord = new Coordinate(14, 15);
			coords.Add(coord);
			coord = new Coordinate(15, 16);
			coords.Add(coord);
			coord = new Coordinate(15, 17);
			coords.Add(coord);
			coord = new Coordinate(15, 18);
			coords.Add(coord);
			coord = new Coordinate(14, 19);
			coords.Add(coord);
			coord = new Coordinate(13, 20);
			coords.Add(coord);
			coord = new Coordinate(12, 21);
			coords.Add(coord);
			coord = new Coordinate(11, 21);
			coords.Add(coord);
			coord = new Coordinate(10, 21);
			coords.Add(coord);
			coord = new Coordinate(9, 20);
			coords.Add(coord);
			coord = new Coordinate(8, 19);
			coords.Add(coord);
			coord = new Coordinate(7, 18);
			coords.Add(coord);
			coord = new Coordinate(7, 17);
			coords.Add(coord);
			coord = new Coordinate(7, 16);
			coords.Add(coord);
			coord = new Coordinate(8, 15);
			coords.Add(coord);
			coord = new Coordinate(9, 14);
			coords.Add(coord);
			coord = new Coordinate(10, 13);
			coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
			LineString ls = gf.CreateLineString(coords);
			return ls;
		}
		public void test_Envelope()
		{
			Polygon polygon = Poly1();

			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(3.0, 1.0);
			coords.Add(coord);
			coord = new Coordinate(7.0, 1.0);
			coords.Add(coord);
			coord = new Coordinate(7.0, 5.0);
			coords.Add(coord);
			coord = new Coordinate(3.0, 5.0);
			coords.Add(coord);
			coord = new Coordinate(3.0, 1.0);
			coords.Add(coord);

			Geometry env = polygon.GetEnvelope() as Geometry;
			Coordinates coords2 = env.GetCoordinates();
			Assertion.AssertEquals("Envelope-1: ", coords[0], coords2[0]);
			Assertion.AssertEquals("Envelope-2: ", coords[1], coords2[1]);
			Assertion.AssertEquals("Envelope-3: ", coords[2], coords2[2]);
			Assertion.AssertEquals("Envelope-4: ", coords[3], coords2[3]);
			Assertion.AssertEquals("Envelope-5: ", coords[4], coords2[4]);

			polygon = Poly2();
			
			coords = new Coordinates();
			coord = new Coordinate(7.0, 13.0);
			coords.Add(coord);
			coord = new Coordinate(15.0, 13.0);
			coords.Add(coord);
			coord = new Coordinate(15.0, 21.0);
			coords.Add(coord);
			coord = new Coordinate(7.0, 21.0);
			coords.Add(coord);
			coord = new Coordinate(7.0, 13.0);
			coords.Add(coord);

			env = polygon.GetEnvelope() as Geometry;
			coords2 = env.GetCoordinates();
			Assertion.AssertEquals("Envelope-6: ", coords[0], coords2[0]);
			Assertion.AssertEquals("Envelope-7: ", coords[1], coords2[1]);
			Assertion.AssertEquals("Envelope-8: ", coords[2], coords2[2]);
			Assertion.AssertEquals("Envelope-9: ", coords[3], coords2[3]);
			Assertion.AssertEquals("Envelope-10: ", coords[4], coords2[4]);
		}
		/// <summary>
		/// Reads a stream and converts the shapefile record to an equilivent geometry object.
		/// </summary>
		/// <param name="file">The stream to read.</param>
		/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
		/// <returns>The Geometry object that represents the shape file record.</returns>
		public override Geometry Read(BigEndianBinaryReader file, GeometryFactory geometryFactory)
		{
			int shapeTypeNum = file.ReadInt32();
			ShapeType shapeType = (ShapeType)Enum.Parse(typeof(ShapeType),shapeTypeNum.ToString());
			if (shapeType != ShapeType.Polygon)
			{
				throw new ShapefileException("Attempting to load a non-polygon as polygon.");
			}

			//read and for now ignore bounds.
			double[] box = new double[4];
			for (int i = 0; i < 4; i++) 
			{
				box[i] = file.ReadDouble();
			}

			int[] partOffsets;
        
			int numParts = file.ReadInt32();
			int numPoints = file.ReadInt32();
			partOffsets = new int[numParts];
			for (int i = 0; i < numParts; i++)
			{
				partOffsets[i] = file.ReadInt32();
			}

			ArrayList shells = new ArrayList();
			ArrayList holes = new ArrayList();

			int start, finish, length;
			for (int part = 0; part < numParts; part++)
			{
				start = partOffsets[part];
				if (part == numParts - 1)
				{
					finish = numPoints;
				}
				else 
				{
					finish = partOffsets[part + 1];
				}
				length = finish - start;
				Coordinates points = new Coordinates();
				points.Capacity=length;
				for (int i = 0; i < length; i++)
				{
					Coordinate external = new Coordinate(file.ReadDouble(), file.ReadDouble() );
					Coordinate internalCoord = geometryFactory.PrecisionModel.ToInternal(external);
					points.Add(internalCoord);
				}
				LinearRing ring = geometryFactory.CreateLinearRing(points);
				//Debug.Assert(ring.IsValid()==false,"Ring is not valid.");
				if (_cga.IsCCW(points))
				{
					holes.Add(ring);
				}
				else 
				{
					shells.Add(ring);
				}
			}

			//now we have a list of all shells and all holes
			ArrayList holesForShells = new ArrayList(shells.Count);
			for (int i = 0; i < shells.Count; i++)
			{
				holesForShells.Add(new ArrayList());
			}
			//find homes
			for (int i = 0; i < holes.Count; i++)
			{
				LinearRing testRing = (LinearRing) holes[i];
				LinearRing minShell = null;
				Envelope minEnv = null;
				Envelope testEnv = testRing.GetEnvelopeInternal();
				Coordinate testPt = testRing.GetCoordinateN(0);
				LinearRing tryRing;
				for (int j = 0; j < shells.Count; j++)
				{
					tryRing = (LinearRing) shells[j];
					Envelope tryEnv = tryRing.GetEnvelopeInternal();
					if (minShell != null) 
					{
						minEnv = minShell.GetEnvelopeInternal();
					}
					bool isContained = false;
					Coordinates coordList = tryRing.GetCoordinates() ;
					if (tryEnv.Contains(testEnv)
						&& (_cga.IsPointInRing(testPt,coordList ) ||
						(PointInList(testPt,coordList)))) 
					{
						isContained = true;
					}
					// check if this new containing ring is smaller than the
					// current minimum ring
					if (isContained) 
					{
						if (minShell == null
							|| minEnv.Contains(tryEnv)) 
						{
							minShell = tryRing;
						}
					}
				}
				//if (minShell==null)
				//{
				//	throw new InvalidOperationException("Could not find shell for a hole. Try a different precision model.");
				//}
			}
			Polygon[] polygons = new Polygon[shells.Count];
			for (int i = 0; i < shells.Count; i++)
			{
				polygons[i] = geometryFactory.CreatePolygon((LinearRing) shells[i], (LinearRing[])((ArrayList) holesForShells[i]).ToArray(typeof(LinearRing)));
			}
        
			if (polygons.Length == 1)
			{
				return polygons[0];
			}
			//it's a multi part
			return geometryFactory.CreateMultiPolygon(polygons);

		}
Exemple #27
0
        /// <summary>
        /// Method to create a NonSimple LinearRing for testing purposes
        /// </summary>
        /// <returns>A LinearRing</returns>
        private LinearRing NonSimple()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate(0, 0);

            coord = new Coordinate(2, 2);
            coords.Add(coord);
            coord = new Coordinate(3, 1);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(7, 5);
            coords.Add(coord);
            coord = new Coordinate(7, 6);
            coords.Add(coord);
            coord = new Coordinate(7, 7);
            coords.Add(coord);
            coord = new Coordinate(7, 8);
            coords.Add(coord);
            coord = new Coordinate(7, 9);
            coords.Add(coord);
            coord = new Coordinate(6, 10);
            coords.Add(coord);
            coord = new Coordinate(5, 11);
            coords.Add(coord);
            coord = new Coordinate(6, 12);
            coords.Add(coord);
            coord = new Coordinate(7, 13);
            coords.Add(coord);
            coord = new Coordinate(8, 14);
            coords.Add(coord);
            coord = new Coordinate(9, 13);
            coords.Add(coord);
            coord = new Coordinate(10, 12);
            coords.Add(coord);
            coord = new Coordinate(10, 11);
            coords.Add(coord);
            coord = new Coordinate(10, 10);
            coords.Add(coord);
            coord = new Coordinate(10, 9);
            coords.Add(coord);
            coord = new Coordinate(9, 8);
            coords.Add(coord);
            coord = new Coordinate(8, 7);
            coords.Add(coord);
            coord = new Coordinate(7, 7);
            coords.Add(coord);
            coord = new Coordinate(6, 7);
            coords.Add(coord);
            coord = new Coordinate(5, 8);
            coords.Add(coord);
            coord = new Coordinate(4, 8);
            coords.Add(coord);
            coord = new Coordinate(3, 7);
            coords.Add(coord);
            coord = new Coordinate(2, 6);
            coords.Add(coord);
            coord = new Coordinate(1, 5);
            coords.Add(coord);
            coord = new Coordinate(2, 4);
            coords.Add(coord);
            coord = new Coordinate(1, 3);
            coords.Add(coord);
            coord = new Coordinate(2, 2);
            coords.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LinearRing lr = gf.CreateLinearRing(coords);
            return lr;
        }
		private Polygon Poly2()
		{
			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(10, 13);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(11, 13);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(12, 13);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(13, 14);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(14, 15);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(15, 16);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(15, 17);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(15, 18);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(14, 19);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(13, 20);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(12, 21);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(11, 21);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(10, 21);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(9, 20);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(8, 19);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(7, 18);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(7, 17);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(7, 16);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(8, 15);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(9, 14);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(10, 13);
			_coords2.Add(coord);
			coords.Add(coord);

			_gf = new GeometryFactory(_precMod, _sRID);
			_exterior2 = _gf.CreateLinearRing(coords);

			coords = new Coordinates();
			coord = new Coordinate(10, 16);
			_coords2.Add(coord);
			coords.Add(coord);
			coord = new Coordinate(11, 17);
			coords.Add(coord);
			_coords2.Add(coord);
			coord = new Coordinate(10, 18);
			coords.Add(coord);
			_coords2.Add(coord);
			coord = new Coordinate(9, 17);
			coords.Add(coord);
			_coords2.Add(coord);
			coord = new Coordinate(10, 16);
			coords.Add(coord);
			_coords2.Add(coord);

			_interior2 = _gf.CreateLinearRing(coords);
			LinearRing[] linearRings = new LinearRing[1];
			linearRings[0] = _interior2;

			_gf = new GeometryFactory();
			Polygon polygon = _gf.CreatePolygon(_exterior2, linearRings);

			return polygon;
		}
		/// <summary>
		/// Reads a stream and converts the shapefile record to an equilivent geometry object.
		/// </summary>
		/// <param name="file">The stream to read.</param>
		/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
		/// <returns>The Geometry object that represents the shape file record.</returns>
		public override Geometry Read(BigEndianBinaryReader file, GeometryFactory geometryFactory)
		{
			int shapeTypeNum = file.ReadInt32();
			ShapeType shapeType = (ShapeType)Enum.Parse(typeof(ShapeType),shapeTypeNum.ToString());
			if (shapeType != ShapeType.Arc)
			{
				throw new ShapefileException("Attempting to load a non-arc as arc.");
			}
			//read and for now ignore bounds.
			double[] box = new double[4];
			for (int i = 0; i < 4; i++) 
			{
				double d= file.ReadDouble();
				box[i] =d;
			}


        
			int numParts = file.ReadInt32();
			int numPoints = file.ReadInt32();
			int[] partOffsets = new int[numParts];
			for (int i = 0; i < numParts; i++)
			{
				partOffsets[i] = file.ReadInt32();
			}
			
			LineString[] lines = new LineString[numParts];
			int start, finish, length;
			for (int part = 0; part < numParts; part++)
			{
				start = partOffsets[part];
				if (part == numParts - 1)
				{
					finish = numPoints;
				}
				else 
				{
					finish = partOffsets[part + 1];
				}
				length = finish - start;
				Coordinates points = new Coordinates();
				points.Capacity=length;
				Coordinate external;
				for (int i = 0; i < length; i++)
				{
					external = new Coordinate(file.ReadDouble(),file.ReadDouble());
					points.Add( geometryFactory.PrecisionModel.ToInternal(external));
				}
				lines[part] = geometryFactory.CreateLineString(points);

			}
			return geometryFactory.CreateMultiLineString(lines);
		}
		/// <summary>
		/// Method to create a NonSimple NonClosed Linestring for testing purposes
		/// </summary>
		/// <returns>A lineString</returns>
		private LineString NonSimpleOpen()
		{
			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(0, 0);

			coord = new Coordinate(2, 2);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(6, 6);
			coords.Add(coord);
			coord = new Coordinate(7, 7);
			coords.Add(coord);
			coord = new Coordinate(8, 8);
			coords.Add(coord);
			coord = new Coordinate(9, 7);
			coords.Add(coord);
			coord = new Coordinate(10, 6);
			coords.Add(coord);
			coord = new Coordinate(10, 5);
			coords.Add(coord);
			coord = new Coordinate(9, 4);
			coords.Add(coord);
			coord = new Coordinate(8, 3);
			coords.Add(coord);
			coord = new Coordinate(7, 4);
			coords.Add(coord);
			coord = new Coordinate(7, 5);
			coords.Add(coord);
			coord = new Coordinate(6, 6);
			coords.Add(coord);
			coord = new Coordinate(5, 7);
			coords.Add(coord);
			coord = new Coordinate(4, 8);
			coords.Add(coord);
			coord = new Coordinate(3, 9);
			coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
			LineString ls = gf.CreateLineString(coords);
			return ls;
		}
Exemple #31
0
        public void test_Geometry()
        {
            LineString[] linestrings = new LineString[2];
            Coordinates coords1 = new Coordinates();
            Coordinate coord = new Coordinate(5,3);
            coords1.Add(coord);
            coord = new Coordinate(4,5);
            coords1.Add(coord);
            coord = new Coordinate(3,4);
            coords1.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString ls = gf.CreateLineString(coords1);
            linestrings[0] = ls;

            Coordinates coords2 = new Coordinates();
            coord = new Coordinate(2,7);
            coords2.Add(coord);
            coord = new Coordinate(9,2);
            coords2.Add(coord);
            coord = new Coordinate(7,9);
            coords2.Add(coord);

            ls = gf.CreateLineString(coords2);
            linestrings[1] = ls;

            MultiLineString mls = gf.CreateMultiLineString(linestrings);

            Assertion.AssertEquals("Geometry-1: ", "LineString:(5, 3, NaN),(4, 5, NaN),(3, 4, NaN)", mls.GetGeometryN(0).ToString());
            Assertion.AssertEquals("Geometry-2: ", "LineString:(2, 7, NaN),(9, 2, NaN),(7, 9, NaN)", mls.GetGeometryN(1).ToString());
        }
Exemple #32
0
		/// <summary>
		/// Creates a projected linear ring.
		/// </summary>
		/// <param name="coordinateTransform">The coordinate transformation to use.</param>
		/// <returns>A projected linear ring.</returns>
		public override Geometry Project(ICoordinateTransformation  coordinateTransform)
		{
			if (coordinateTransform==null)
			{
				throw new ArgumentNullException("coordinateTransform");
			}
			if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection))
			{
				throw new ArgumentException("CoordinateTransform must be a MapProjection.");
			}

			int sourceSRID = int.Parse(coordinateTransform.SourceCS.AuthorityCode);
			int targetSRID = int.Parse(coordinateTransform.TargetCS.AuthorityCode);
			MapProjection projection = (MapProjection)coordinateTransform.MathTransform;
			int newSRID = GetNewSRID(coordinateTransform);

			Coordinates projectedCoordinates = new Coordinates();
			double x=0.0;
			double y=0.0;
			Coordinate projectedCoordinate;
			Coordinate external;
			Coordinate coordinate;
			for(int i=0; i < _points.Count; i++)
			{
				coordinate = _points[i];
				external = _geometryFactory.PrecisionModel.ToExternal( coordinate );
				if (this._SRID==sourceSRID)
				{
					projection.MetersToDegrees(external.X, external.Y, out x, out y);	
				}
				else if (this._SRID==targetSRID)
				{
					
					projection.DegreesToMeters(external.X, external.Y, out x, out y);
				}
				projectedCoordinate = _geometryFactory.PrecisionModel.ToInternal(new Coordinate( x, y) );
				projectedCoordinates.Add( projectedCoordinate );
			}
			return new LinearRing( projectedCoordinates, this.PrecisionModel, newSRID);
		}
        private GeometryCollection CreateCollection3()
        {
            //create a new geometries array
            Geometry[] geom = new Geometry[10];

            Coordinate coordinate = new Coordinate();
            Coordinates coords = new Coordinates();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            Point point = gf.CreatePoint(coordinate);

            LineString lineString = gf.CreateLineString(coords);

            for(int c = 0; c < 5; c++)
            {
                for(int i = c; i < c+5; i++)
                {
                    //if this isn't here the coordinates for all the points are reset every time the coordinate is reset
                    coordinate = new Coordinate();
                    //make the x coordinate equal to the iterator
                    coordinate.X = (double)i;
                    //make the y coordinate equal to the iterator plus 10
                    coordinate.Y = (double)i + 10;
                    coords.Add(coordinate);
                }
                lineString = gf.CreateLineString(coords);
                geom[c] = lineString;
            }
            for(int i = 5; i < 10; i++)
            {
                //if this isn't here the coordinates for all the points are reset every time the coordinate is reset
                coordinate = new Coordinate();
                //make the x coordinate equal to the iterator
                coordinate.X = (double)i;
                //make the y coordinate equal to the iterator plus 10
                coordinate.Y = (double)i + 10;
                //create a new point to put in the geometry
                point = gf.CreatePoint(coordinate);
                //put the point in the geometies
                geom[i] = point;
            }
            //put the geometries into a geometry collection
            GeometryCollection geoColl = gf.CreateGeometryCollection(geom);

            return geoColl;
        }
Exemple #34
0
		/// <summary>
		///		An alternative to Stack.ToArray, which is not present in earlier versions of Java.
		/// </summary>
		/// <param name="stack"></param>
		/// <returns></returns>
		protected Coordinates ToCoordinateArray(Stack stack) 
		{
			
			Coordinates coordinates = new Coordinates();
			foreach(object obj in stack)
			{
				Coordinate coordinate = (Coordinate)obj;
				coordinates.Add( coordinate);
			}
			// because taking stuff of a stack, need to reverse resulting array.
			// JTS code used array indexing to make new array, but .Net's Stack does not allow array indexing.
			coordinates.Reverse();
			return coordinates;
		}
Exemple #35
0
        private LinearRing ThrowsException()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord ;//Coordinate(0, 0);

            coord = new Coordinate(10, 13);
            coords.Add(coord);
            coord = new Coordinate(11, 13);
            coords.Add(coord);
            coord = new Coordinate(12, 13);
            coords.Add(coord);
            coord = new Coordinate(13, 14);
            coords.Add(coord);
            coord = new Coordinate(14, 15);
            coords.Add(coord);
            coord = new Coordinate(15, 16);
            coords.Add(coord);
            coord = new Coordinate(15, 17);
            coords.Add(coord);
            coord = new Coordinate(15, 18);
            coords.Add(coord);
            coord = new Coordinate(14, 19);
            coords.Add(coord);
            coord = new Coordinate(13, 20);
            coords.Add(coord);
            coord = new Coordinate(12, 21);
            coords.Add(coord);
            coord = new Coordinate(11, 21);
            coords.Add(coord);
            coord = new Coordinate(10, 21);
            coords.Add(coord);
            coord = new Coordinate(9, 20);
            coords.Add(coord);
            coord = new Coordinate(8, 19);
            coords.Add(coord);
            coord = new Coordinate(7, 18);
            coords.Add(coord);
            coord = new Coordinate(7, 17);
            coords.Add(coord);
            coord = new Coordinate(7, 16);
            coords.Add(coord);
            coord = new Coordinate(8, 15);
            coords.Add(coord);
            coord = new Coordinate(9, 14);
            coords.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LinearRing lr = gf.CreateLinearRing(coords);
            return lr;
        }
Exemple #36
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="pts"></param>
		/// <returns></returns>
		private Coordinates Reduce(Coordinates pts) 
		{
	
			BigQuad bigQuad = this.BigQuadrant(pts);

			// Build a linear ring defining a big poly.
			Coordinates bigPoly = new Coordinates();
			bigPoly.Add(bigQuad._westmost);
			if (!bigPoly.Contains(bigQuad._northmost)) 
			{
				bigPoly.Add(bigQuad._northmost);
			}
			if (!bigPoly.Contains(bigQuad._eastmost)) 
			{
				bigPoly.Add(bigQuad._eastmost);
			}
			if (!bigPoly.Contains(bigQuad._southmost)) 
			{
				bigPoly.Add(bigQuad._southmost);
			}
			if (bigPoly.Count < 3) 
			{
				return pts;
			}
			bigPoly.Add(bigQuad._westmost);
			LinearRing bQ = new LinearRing(bigPoly,
				_geometry.PrecisionModel, _geometry.GetSRID());

			// load an array with all points not in the big poly
			// and the defining points.
			Coordinates reducedSet = new Coordinates(bigPoly);
			for (int i = 0; i < pts.Count; i++) 
			{
				if (_pointLocator.Locate(pts[i], bQ) == Location.Exterior) 
				{
					reducedSet.Add(pts[i]);
				}
			}
			//Coordinates rP = (Coordinates) reducedSet.toArray(new Coordinate[0]);

			// Return this array as the reduced problem.
			return reducedSet;
		}
Exemple #37
0
        private MultiLineString closedMLS()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[2];

            coord = new Coordinate(10, 13);
            coords.Add(coord);
            coord = new Coordinate(11, 13);
            coords.Add(coord);
            coord = new Coordinate(12, 13);
            coords.Add(coord);
            coord = new Coordinate(13, 14);
            coords.Add(coord);
            coord = new Coordinate(14, 15);
            coords.Add(coord);
            coord = new Coordinate(15, 16);
            coords.Add(coord);
            coord = new Coordinate(15, 17);
            coords.Add(coord);
            coord = new Coordinate(15, 18);
            coords.Add(coord);
            coord = new Coordinate(14, 19);
            coords.Add(coord);
            coord = new Coordinate(13, 20);
            coords.Add(coord);
            coord = new Coordinate(12, 21);
            coords.Add(coord);
            coord = new Coordinate(11, 21);
            coords.Add(coord);
            coord = new Coordinate(10, 21);
            coords.Add(coord);
            coord = new Coordinate(9, 20);
            coords.Add(coord);
            coord = new Coordinate(8, 19);
            coords.Add(coord);
            coord = new Coordinate(7, 18);
            coords.Add(coord);
            coord = new Coordinate(7, 17);
            coords.Add(coord);
            coord = new Coordinate(7, 16);
            coords.Add(coord);
            coord = new Coordinate(8, 15);
            coords.Add(coord);
            coord = new Coordinate(9, 14);
            coords.Add(coord);
            coord = new Coordinate(10, 13);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            coords = new Coordinates();
            coord = new Coordinate(5, 1);
            coords.Add(coord);
            coord = new Coordinate(6, 2);
            coords.Add(coord);
            coord = new Coordinate(7, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 1);
            coords.Add(coord);
            ls[1] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
Exemple #38
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="coordinates">
		///		The vertices of a linear ring, which may or may not be flattened (i.e. vertices collinear)
		///	</param>
		/// <returns>
		///		A 2-vertex LineStringif the vertices are collinear; otherwise, a Polygon with 
		///		unnecessary (collinear) vertices removed
		///	</returns>
		private Geometry LineOrPolygon(Coordinates coordinates) 
		{
			coordinates = CleanRing(coordinates);
			if (coordinates.Count == 3) 
			{
				Coordinates coords = new Coordinates();
				coords.Add(coordinates[0]);
				coords.Add(coordinates[1]);
				return new LineString(coords,
					_geometry.PrecisionModel, _geometry.GetSRID());
			}

			LinearRing linearRing = new LinearRing(coordinates,
				_geometry.PrecisionModel, _geometry.GetSRID());
			return new Polygon(linearRing, _geometry.PrecisionModel, _geometry.GetSRID());
		}
Exemple #39
0
        private MultiLineString nonSimpleMLS()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[1];

            coord = new Coordinate(2, 2);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(7, 7);
            coords.Add(coord);
            coord = new Coordinate(8, 8);
            coords.Add(coord);
            coord = new Coordinate(9, 7);
            coords.Add(coord);
            coord = new Coordinate(10, 6);
            coords.Add(coord);
            coord = new Coordinate(10, 5);
            coords.Add(coord);
            coord = new Coordinate(9, 4);
            coords.Add(coord);
            coord = new Coordinate(8, 3);
            coords.Add(coord);
            coord = new Coordinate(7, 4);
            coords.Add(coord);
            coord = new Coordinate(7, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(5, 7);
            coords.Add(coord);
            coord = new Coordinate(4, 8);
            coords.Add(coord);
            coord = new Coordinate(3, 9);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
Exemple #40
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="original">
		///		The vertices of a linear ring, which may or may not be flattened (i.e. vertices collinear)
		/// </param>
		/// <returns>
		///		The coordinates with unnecessary (collinear) vertices removed
		/// </returns>
		private Coordinates CleanRing(Coordinates original) 
		{
			if (!(original[0]== original[original.Count - 1]))
			{
				throw new InvalidProgramException("Start and end points of ring are not the same.");
			}
			Coordinates cleanedRing = new Coordinates();
			Coordinate previousDistinctCoordinate = null;
			for (int i = 0; i <= original.Count - 2; i++) 
			{
				Coordinate currentCoordinate = original[i];
				Coordinate nextCoordinate = original[i+1];
				if (currentCoordinate.Equals(nextCoordinate)) 
				{
					continue;
				}
				if (previousDistinctCoordinate != null
					&& IsBetween(previousDistinctCoordinate, currentCoordinate, nextCoordinate)) 
				{
					continue;
				}
				cleanedRing.Add(currentCoordinate);
				previousDistinctCoordinate = currentCoordinate;
			}
			cleanedRing.Add(original[original.Count - 1]);
			//Coordinates cleanedRingCoordinates = new Coordinate[cleanedRing.Count];
			//return (Coordinates) cleanedRing.toArray(cleanedRingCoordinates);
			return cleanedRing;

		}