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);
		}
		/// <summary>
		/// Initializes a new instance of the MultiLineString class.
		/// </summary>
		/// <param name="lineStrings">
		/// The LineStrings for this MultiLineString, or null or an 
		/// empty array to create the empty MultiLineString.  Elements may be empty 
		/// LineStrings, but not nulls.
		/// </param>
		/// <param name="precisionModel">
		/// The specification of the grid of allowable points for this MultiLineString.
		/// </param>
		/// <param name="SRID">
		/// The ID of the Spatial Reference System used by this MultiLineString.
		/// </param>
		internal MultiLineString(LineString[] lineStrings, PrecisionModel precisionModel, int SRID)
			: base(lineStrings, precisionModel, SRID)
		{
			if(lineStrings == null)
			{
				lineStrings = new LineString[]{};
			}
			if(HasNullElements(lineStrings))
			{
				throw new ArgumentException("MultiLineStrings cannot have nulls.");
			}
			_geometries = lineStrings;
		}
Example #3
0
		private void ComputeMinDistance(LineString line0, LineString line1)
		{
			if (line0.GetEnvelopeInternal().Distance(line1.GetEnvelopeInternal())> _minDistance)
				return;
			Coordinates coord0 = line0.GetCoordinates();
			Coordinates coord1 = line1.GetCoordinates();
			// brute force approach!
			for (int i = 0; i < coord0.Count - 1; i++) 
			{
				for (int j = 0; j < coord1.Count - 1; j++) 
				{
					double dist = CGAlgorithms.DistanceLineLine(
						coord0[i], coord0[i + 1],
						coord1[j], coord1[j + 1] );
					UpdateMinDistance(dist);
				}
			}
		}
		/// <summary>
		/// Add a LineString to the graph
		/// </summary>
		/// <param name="line"></param>
		private void AddLineString(LineString line)
		{
			if (_distance <= 0.0) return;
			Coordinates coords = Coordinates.RemoveRepeatedPoints(line.GetCoordinates());
		
			ArrayList lineList = _lineBuilder.GetLineBuffer(coords, _distance);
			AddEdges(lineList, Location.Exterior, Location.Interior);
			
		}
Example #5
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;
        }
Example #6
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());
        }
		protected void AppendLineStringTextAbsolute(LineString lineString, TextWriter writer)
		{
			
			if (lineString.IsEmpty()) 
			{
				//writer.Write("EMPTY");
			}
			else 
			{
				writer.Write(" M ");
				AppendCoordinate(lineString.GetCoordinateN(0), writer, _precisionModel);
				for (int i = 1; i < lineString.GetNumPoints(); i++) 
				{
					writer.Write(" L ");
					AppendCoordinate(lineString.GetCoordinateN(i), writer, _precisionModel);
					if (i%5==4)
					{
						writer.WriteLine();
					}
				}
				
			}
		}
		public void AppendLineStringText(LineString lineString, TextWriter writer)
		{
			if (_useRelative)
			{
				AppendLineStringTextRelative(lineString, writer);
			}
			else
			{
				AppendLineStringTextAbsolute(lineString, writer);
			}
		}
Example #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public Edge FindEdge( LineString line )
 {
     return (Edge) _lineEdgeMap[line];
 }
Example #10
0
		/// <summary>
		/// Tests if LineString is simple.
		/// </summary>
		/// <param name="geometry">Geometry to test.  Must be of type LineString.</param>
		/// <returns>Returns True if geometry is simple.</returns>
		public bool IsSimple( LineString geometry )
		{
			return IsSimpleLinearGeometry(geometry);
		}
		/// <summary>
		/// Creates a multilinestring from the wkb.
		/// </summary>
		/// <returns>A geometry.</returns>
		private Geometry CreateWKBMultiLineString()
		{
			//Get the number of linestrings in this multilinestring.
			int numLineStrings = (int)_bReader.ReadUInt32();

            //Create a new array for the linestrings .
			LineString[] lineStrings = new LineString[numLineStrings];
            
			//Loop on the number of linestrings.
			for(int i = 0; i < numLineStrings; i++)
			{
				//read Point header
				_bReader.ReadByte();
				_bReader.ReadUInt32();

				//Create the next linestring and add it to the array.
				lineStrings[i] = (LineString)CreateWKBLineString();
			}
			//Create and return the MultiLineString.
			return _geometryFactory.CreateMultiLineString(lineStrings);
		}
		/// <summary>
		/// Writes a linestring.
		/// </summary>
		/// <param name="ls">The linestring to be written.</param>
		private void WriteLineString(LineString ls, byte format)
		{
			//Write the number of points in this linestring.
			_bWriter.Write( ls.GetNumPoints() );

			//Loop on each set of coordinates.
			foreach(Coordinate coord in ls.GetCoordinates() )
			{
				//Create a new point from the coordinates & write it.
				WritePoint(_geometryFactory.CreatePoint(coord));
			}
		}
		/// <summary>
		/// Create a new multilinestring given an array of linestrings.
		/// </summary>
		/// <param name="lineStrings">The array of linestrings to be used to create the multilinestring.</param>
		/// <returns>A new multilinestring.</returns>
		public MultiLineString CreateMultiLineString(LineString[] lineStrings) 
		{
			return new MultiLineString(lineStrings, _precisionModel, _SRID);
		}
		/// <summary>
		/// Converts the List to an array.
		/// </summary>
		/// <param name="lineStrings">The List to convert.</param>
		/// <returns>The List in array format.</returns>
		public static LineString[] ToLineStringArray(ArrayList lineStrings) 
		{
			LineString[] lineStringArray = new LineString[lineStrings.Count];
			return (LineString[]) lineStrings.ToArray(typeof(LineString));
		}
Example #15
0
 /// <summary>
 /// Converts the List to an array.
 /// </summary>
 /// <param name="lineStrings">The List to convert.</param>
 /// <returns>The List in array format.</returns>
 public static LineString[] ToLineStringArray(ArrayList lineStrings)
 {
     LineString[] lineStringArray = new LineString[lineStrings.Count];
     return((LineString[])lineStrings.ToArray(typeof(LineString)));
 }
		/// <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>
		/// Converts a LineString to SVG path element. 
		/// </summary>
		/// <param name="lineString">The LineString to process.</param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendLineStringTaggedText(LineString lineString, TextWriter writer)
		{
			AppendPath(writer);
			AppendLineStringText(lineString,  writer);
			AppendEndPath(writer);	
		}
Example #18
0
        private void AddLineString(LineString line)
        {
            Coordinates coord = line.GetCoordinates();

            // add the edge for the LineString
            // line edges do not have locations for their left and right sides
            Edge e = new Edge( coord, new Label( _argIndex, Location.Interior ) );
            _lineEdgeMap[ line]=e ;
            InsertEdge( e );
            /**
             * Add the boundary points of the LineString, if any.
             * Even if the LineString is closed, add both points as if they were endpoints.
             * This allows for the case that the node already exists and is a boundary point.
             */
            if( coord.Count < 2 )
            {
                throw new InvalidOperationException("Found LineString with single point");
            }
            InsertBoundaryPoint( _argIndex, coord[0] );
            InsertBoundaryPoint( _argIndex, coord[coord.Count- 1] );
        }
		/// <summary>
		/// Converts a LineString to &lt;LineString Text&gt; format, then
		/// Appends it to the writer.
		/// </summary>
		/// <param name="lineString">The LineString to process.</param>
		/// <param name="writer">The output stream to Append to.</param>
		public void AppendLineStringTextRelative(LineString lineString, TextWriter writer)
		{
			
			if (lineString.IsEmpty()) 
			{
				//writer.Write("EMPTY");
			}
			else 
			{
				writer.Write(" M ");
				double currentX = lineString.GetCoordinateN(0).X; 
				double currentY = lineString.GetCoordinateN(0).Y;
				double x=0;
				double y=0;
				AppendCoordinate(lineString.GetCoordinateN(0), writer, _precisionModel);
				Coordinate relativeCoordinate = new Coordinate();
				writer.Write(" l ");
				for (int i = 1; i < lineString.GetNumPoints(); i++) 
				{
					x = lineString.GetCoordinateN(i).X;
					y = lineString.GetCoordinateN(i).Y;
					relativeCoordinate.X=  x- currentX;
					relativeCoordinate.Y=  y - currentY;
					AppendCoordinate(relativeCoordinate, writer, _precisionModel);
					currentX = x;
					currentY = y;	
					if (i%5==4)
					{
						writer.WriteLine();
					}
				}
				
			}
		}
		/// <summary>
		/// Converts a LineString to LineString tagged text format, 
		/// </summary>
		/// <param name="lineString">The LineString to process.</param>
		/// <param name="level"></param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendLineStringTaggedText(LineString lineString, int level, StringWriter writer)
		{
			
			writer.Write("LINESTRING ");
			AppendLineStringText(lineString, level, false, writer);
			
		}
Example #21
0
		} //private void UpdateLocationInfo( int loc )

		/// <summary>
		/// 
		/// </summary>
		/// <param name="p"></param>
		/// <param name="l"></param>
		/// <returns></returns>
		private int Locate( Coordinate p, LineString l )
		{
			Coordinates pt = l.GetCoordinates();
			if ( !l.IsClosed() ) 
			{
				if ( p.Equals( pt[0] ) || p.Equals( pt[pt.Count - 1] ) ) 
				{
					return Location.Boundary;
				}
			}
			if ( _cga.IsOnLine( p, pt ) )
			{
				return Location.Interior;
			}
			return Location.Exterior;
		} // private int Locate( Coordinate p, LineString l )
		/// <summary>
		/// Converts a LineString to &lt;LineString Text&gt; format, then
		/// Appends it to the writer.
		/// </summary>
		/// <param name="lineString">The LineString to process.</param>
		/// <param name="level"></param>
		/// <param name="doIndent"></param>
		/// <param name="writer">The output stream to Append to.</param>
		protected void AppendLineStringText(LineString lineString, int level, bool doIndent, StringWriter writer)
		{
			
			if ( lineString.IsEmpty() ) 
			{
				writer.Write("EMPTY");
			}
			else 
			{
				if (doIndent)
				{
					Indent(level, writer);
				}
				writer.Write("(");
				for (int i = 0; i < lineString.GetNumPoints(); i++) 
				{
					if (i > 0) 
					{
						writer.Write(", ");
						if (i % 10 == 0) Indent(level + 2, writer);
					}
					//AppendCoordinate(lineString.GetCoordinateN(i), writer, lineString.PrecisionModel);
					AppendCoordinate( lineString.GetCoordinates()[i], writer, lineString.PrecisionModel );
				}
				writer.Write(")");
			}
			
		}
Example #23
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;
        }
		/// <summary>
		/// Projects a multi line string.
		/// </summary>
		/// <param name="coordinateTransform">The coordinate transformation to use.</param>
		/// <returns>A projected multi line string.</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.");
			}

			
			LineString[] projectedlines = new LineString[_geometries.Length];
			IGeometry projectedline;
			for(int i=0; i<_geometries.Length; i++)
			{				
				projectedline = _geometries[i].Project(coordinateTransform);
				projectedlines[i] = (LineString)projectedline;				
			}
			return _geometryFactory.CreateMultiLineString(projectedlines);
		}
Example #25
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;
        }
Example #26
0
		private void CheckValid(LineString g)
		{
			GeometryGraph graph = new GeometryGraph(0, g);
			CheckTooFewPoints(graph);
		}