Esempio n. 1
0
		/// <summary>
		/// Initializes a new instance of the BufferOp class.
		/// </summary>
		/// <param name="g0"></param>
		public BufferOp(Geometry g0) : base(g0)
		{
			
			_graph = new PlanarGraph(new OverlayNodeFactory());
			_geomFact = new GeometryFactory( g0.PrecisionModel,	g0.GetSRID() );
		
		}
Esempio n. 2
0
		///<summary>
		/// Throws an exception if the spatial reference IDs differ  
		///</summary>
		///<param name="geometry">The Geometry with which to compare this Geometry.</param>
		///<exception cref="ArgumentException">If the two Geometrys have *different SRIDs</exception>
		protected virtual void CheckEqualSRID(Geometry geometry) 
		{
			if ( _SRID != geometry.GetSRID() ) 
			{
				throw new ArgumentException("Expected SRIDs to be equal, but they were not");
			}
		}
Esempio n. 3
0
		/// <summary>
		/// Gets the convex hull for the given geometry.
		/// </summary>
		/// <param name="geometry"></param>
		/// <returns></returns>
		public Geometry GetConvexHull(Geometry geometry) 
		{

			this._geometry = geometry;
			UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter();
			geometry.Apply(filter);
			Coordinates pts = filter.GetCoordinates();

			if (pts.Count == 0) 
			{
				return new GeometryCollection(new Geometry[]{},
					geometry.PrecisionModel, geometry.GetSRID());
			}
			if (pts.Count == 1) 
			{
				return new Point(pts[0], geometry.PrecisionModel, geometry.GetSRID());
			}
			if (pts.Count == 2) 
			{
				return new LineString(pts, geometry.PrecisionModel, geometry.GetSRID());
			}

			// sort points for Graham scan.
			Coordinates pspts;
			if (pts.Count > 10) 
			{
				//Probably should be somewhere between 50 and 100?
				Coordinates rpts = Reduce(pts);
				pspts = PreSort(rpts);
			}
			else 
			{
				pspts = PreSort(pts);
			}

			// Use Graham scan to find convex hull.
			Stack cHS = GrahamScan(pspts);

			// Convert stack to an array.
			Coordinates cH = ToCoordinateArray(cHS);

			// Convert array to linear ring.
			//awcreturn lineOrPolygon(cH);
			return LineOrPolygon(cH);

		}
Esempio n. 4
0
        /// <summary>
        /// Applies the projection to the coordinates.
        /// </summary>
        /// <param name="geometry">The geometry object to apply the filter to.</param>
        public void Filter(Geometry geometry)
        {
            /*if (geometry is Polygon)
             * {
             *      Polygon polygon = (Polygon)geometry;
             *      Filter(polygon.Shell);
             *      foreach(LinearRing linearring in polygon.Holes)
             *      {
             *              Filter(linearring);
             *      }
             * }*/
            if (geometry is LinearRing || geometry is LineString || geometry is Point)
            {
                int           sourceSRID = int.Parse(_coordinateTransform.SourceCS.AuthorityCode);
                int           targetSRID = int.Parse(_coordinateTransform.TargetCS.AuthorityCode);
                MapProjection projection = (MapProjection)_coordinateTransform.MathTransform;

                Coordinates projectedCoordinates = new Coordinates();
                double      x = 0.0;
                double      y = 0.0;
                Coordinate  coordinate;
                for (int i = 0; i < geometry.GetCoordinates().Count; i++)
                {
                    coordinate = geometry.GetCoordinates()[i];
                    if (geometry.GetSRID() == sourceSRID)
                    {
                        projection.MetersToDegrees(coordinate.X, coordinate.Y, out x, out y);
                    }
                    else if (geometry.GetSRID() == targetSRID)
                    {
                        projection.DegreesToMeters(coordinate.X, coordinate.Y, out x, out y);
                    }
                    coordinate.X = x;
                    coordinate.Y = y;
                }
            }

            /*else
             * {
             *      throw new NotSupportedException(geometry.GetType().Name);
             * }*/
        }
		/// <summary>
		/// Applies the projection to the coordinates.
		/// </summary>
		/// <param name="geometry">The geometry object to apply the filter to.</param>
		public void Filter(Geometry geometry)
		{
			/*if (geometry is Polygon)
			{
				Polygon polygon = (Polygon)geometry;
				Filter(polygon.Shell);
				foreach(LinearRing linearring in polygon.Holes)
				{
					Filter(linearring);
				}
			}*/
			if (geometry is LinearRing || geometry is LineString || geometry is Point)
			{	
				int sourceSRID = int.Parse(_coordinateTransform.SourceCS.AuthorityCode);
				int targetSRID = int.Parse(_coordinateTransform.TargetCS.AuthorityCode);
				MapProjection projection = (MapProjection)_coordinateTransform.MathTransform;

				Coordinates projectedCoordinates = new Coordinates();
				double x=0.0;
				double y=0.0;
				Coordinate coordinate;
				for(int i=0; i < geometry.GetCoordinates().Count; i++)
				{
					coordinate = geometry.GetCoordinates()[i];
					if (geometry.GetSRID() == sourceSRID)
					{
						projection.MetersToDegrees(coordinate.X, coordinate.Y, out x, out y);	
					}
					else if (geometry.GetSRID() == targetSRID)
					{
					
						projection.DegreesToMeters(coordinate.X, coordinate.Y, out x, out y);
					}
					coordinate.X = x;
					coordinate.Y = y;
				}
			}
			/*else
			{
				throw new NotSupportedException(geometry.GetType().Name);
			}*/
		}
Esempio n. 6
0
		/// <summary>
		/// Writes a Geometry to the given binary wirter.
		/// </summary>
		/// <param name="geometry">The geometry to write.</param>
		/// <param name="file">The file stream to write to.</param>
		/// <param name="geometryFactory">The geometry factory to use.</param>
		public override void Write(Geometry geometry, System.IO.BinaryWriter file, GeometryFactory geometryFactory)
		{
			if (geometry.IsValid()==false)
			{
				Trace.WriteLine("Invalid polygon being written.");
			}
			GeometryCollection multi;
			if(geometry is GeometryCollection)
			{
				multi = (GeometryCollection) geometry;
			}
			else 
			{
				GeometryFactory gf = new GeometryFactory(geometry.PrecisionModel, geometry.GetSRID());
				//multi = new MultiPolygon(new Polygon[]{(Polygon) geometry}, geometry.PrecisionModel, geometry.GetSRID());
				multi = gf.CreateMultiPolygon( new Polygon[]{(Polygon) geometry} );
			}
			//file.setLittleEndianMode(true);
			file.Write(int.Parse(Enum.Format(typeof(ShapeType),this.ShapeType,"d")));
        
			Envelope box = multi.GetEnvelopeInternal();
			Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel,  box);
			file.Write(bounds.MinX);
			file.Write(bounds.MinY);
			file.Write(bounds.MaxX);
			file.Write(bounds.MaxY);
        
			int numParts = GetNumParts(multi);
			int numPoints = multi.GetNumPoints();
			file.Write(numParts);
			file.Write(numPoints);
        
			
			// write the offsets to the points
			int offset=0;
			for (int part = 0; part < multi.Count; part++)
			{
				// offset to the shell points
				Polygon polygon = (Polygon)multi[part];
				file.Write(offset);
				offset = offset + polygon.Shell.GetNumPoints();
				// offstes to the holes
				foreach (LinearRing ring in polygon.Holes)
				{
					file.Write(offset);
					offset = offset + ring.GetNumPoints();
				}	
			}


			// write the points 
			for (int part = 0; part < multi.Count; part++)
			{
				Polygon poly = (Polygon)multi[part];
				Coordinates points = poly.Shell.GetCoordinates();
				if (_cga.IsCCW(points)==true)
				{
					//points = points.ReverseCoordinateOrder();
				}
				WriteCoords(points, file, geometryFactory);
				foreach(LinearRing ring in poly.Holes)
				{
					Coordinates points2 = ring.GetCoordinates();
					if (_cga.IsCCW(points2)==false)
					{
						//points2 = points2.ReverseCoordinateOrder();
					}
					WriteCoords(points2, file, geometryFactory);
				}
			}
		}
Esempio n. 7
0
		public OverlayOp( Geometry g0, Geometry g1 ) : base( g0, g1 )
		{
			_graph = new PlanarGraph( new OverlayNodeFactory() );
			_geomFact = new GeometryFactory( g0.PrecisionModel, g0.GetSRID() );
		} // public OverlayOp( Geometry g0, Geometry g1 ) : base( g0, g1 )
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the GeometryGraph class.
 /// </summary>
 public GeometryGraph( int argIndex, Geometry parentGeometry )
 {
     _argIndex = argIndex;
     _parentGeometry = parentGeometry;
     if ( parentGeometry != null )
     {
         _precisionModel = parentGeometry.PrecisionModel;
         _SRID = parentGeometry.GetSRID();
         Add( parentGeometry );
     }
 }