예제 #1
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);

		}
		public static ArrayList GetLines(Geometry geom)
		{
			ArrayList lines = new ArrayList();
			geom.Apply(new LineExtracterFilter(lines));
			return lines;
		}
		public static ArrayList GetPoints(Geometry geom)
		{
			ArrayList pts = new ArrayList();
			geom.Apply(new PointExtracterFilter(pts));
			return pts;
		}
		public static ArrayList GetPolygons(Geometry geom)
		{
			ArrayList comps = new ArrayList();
			geom.Apply(new PolygonExtracterFilter(comps));
			return comps;
		}
		public static ArrayList GetCoordinates(Geometry geom)
		{
			ArrayList pts = new ArrayList();
			geom.Apply(new ConnectedElementPointFilter(pts));
			return pts;
		}