/// <summary> /// Returns the distance between this geometry instance and another geometry, as /// measured in the spatial reference system of this instance. /// </summary> /// <param name="geom"></param> /// <returns></returns> public override double Distance(Geometry geom) { if (geom.GetType() == typeof(Point3D)) { Point3D p = geom as Point3D; return(Math.Sqrt(Math.Pow(X - p.X, 2) + Math.Pow(Y - p.Y, 2) + Math.Pow(Z - p.Z, 2))); } else { return(base.Distance(geom)); } }
/// <summary> /// Returns the distance between this geometry instance and another geometry, as /// measured in the spatial reference system of this instance. /// </summary> /// <param name="geom"></param> /// <returns></returns> public override double Distance(Geometry geom) { if (geom.GetType() == typeof(RgPoint)) { RgPoint p = geom as RgPoint; return(Math.Sqrt(Math.Pow(X - p.X, 2) + Math.Pow(Y - p.Y, 2))); } else { throw new Exception("The method or operation is not implemented for this geometry type."); } }
/// <summary> /// Writes the type number for this geometry. /// </summary> /// <param name="geometry">The geometry to determine the type of.</param> /// <param name="bWriter">Binary Writer</param> /// <param name="byteorder">Byte order</param> private static void WriteType(RGeos.Geometries.Geometry geometry, BinaryWriter bWriter, WkbByteOrder byteorder) { //Determine the type of the geometry. switch (geometry.GetType().FullName) { //Points are type 1. case "RGeos.Geometries.Point": WriteUInt32((uint)WKBGeometryType.wkbPoint, bWriter, byteorder); break; //Linestrings are type 2. case "RGeos.Geometries.LineString": WriteUInt32((uint)WKBGeometryType.wkbLineString, bWriter, byteorder); break; //Polygons are type 3. case "RGeos.Geometries.Polygon": WriteUInt32((uint)WKBGeometryType.wkbPolygon, bWriter, byteorder); break; //Mulitpoints are type 4. case "RGeos.Geometries.MultiPoint": WriteUInt32((uint)WKBGeometryType.wkbMultiPoint, bWriter, byteorder); break; //Multilinestrings are type 5. case "RGeos.Geometries.MultiLineString": WriteUInt32((uint)WKBGeometryType.wkbMultiLineString, bWriter, byteorder); break; //Multipolygons are type 6. case "RGeos.Geometries.MultiPolygon": WriteUInt32((uint)WKBGeometryType.wkbMultiPolygon, bWriter, byteorder); break; //Geometrycollections are type 7. case "RGeos.Geometries.GeometryCollection": WriteUInt32((uint)WKBGeometryType.wkbGeometryCollection, bWriter, byteorder); break; //If the type is not of the above 7 throw an exception. default: throw new ArgumentException("Invalid Geometry Type"); } }
/// <summary> /// Writes the geometry to the binary writer. /// </summary> /// <param name="geometry">The geometry to be written.</param> /// <param name="bWriter"></param> /// <param name="byteorder">Byte order</param> private static void WriteGeometry(RGeos.Geometries.Geometry geometry, BinaryWriter bWriter, WkbByteOrder byteorder) { switch (geometry.GetType().FullName) { //Write the point. case "RGeos.Geometries.Point": WritePoint((RgPoint)geometry, bWriter, byteorder); break; case "RGeos.Geometries.LineString": LineString ls = (LineString)geometry; WriteLineString(ls, bWriter, byteorder); break; case "RGeos.Geometries.Polygon": WritePolygon((Polygon)geometry, bWriter, byteorder); break; //Write the Multipoint. case "RGeos.Geometries.MultiPoint": WriteMultiPoint((MultiPoint)geometry, bWriter, byteorder); break; //Write the Multilinestring. case "RGeos.Geometries.MultiLineString": WriteMultiLineString((MultiLineString)geometry, bWriter, byteorder); break; //Write the Multipolygon. case "RGeos.Geometries.MultiPolygon": WriteMultiPolygon((MultiPolygon)geometry, bWriter, byteorder); break; //Write the Geometrycollection. case "RGeos.Geometries.GeometryCollection": WriteGeometryCollection((GeometryCollection)geometry, bWriter, byteorder); break; //If the type is not of the above 7 throw an exception. default: throw new ArgumentException("Invalid Geometry Type"); } }
/// <summary> /// Returns true if otherGeometry is of the same type and defines the same point set as the source geometry. /// </summary> /// <param name="g1">source geometry</param> /// <param name="g2">other Geometry</param> /// <returns></returns> public static bool Equals(Geometry g1, Geometry g2) { if (g1 == null && g2 == null) { return(true); } if (g1 == null || g2 == null) { return(false); } if (g1.GetType() != g2.GetType()) { return(false); } if (g1 is RgPoint) { return((g1 as RgPoint).Equals(g2 as RgPoint)); } else if (g1 is LineString) { return((g1 as LineString).Equals(g2 as LineString)); } else if (g1 is Polygon) { return((g1 as Polygon).Equals(g2 as Polygon)); } else if (g1 is MultiPoint) { return((g1 as MultiPoint).Equals(g2 as MultiPoint)); } else if (g1 is MultiLineString) { return((g1 as MultiLineString).Equals(g2 as MultiLineString)); } else if (g1 is MultiPolygon) { return((g1 as MultiPolygon).Equals(g2 as MultiPolygon)); } else { throw new ArgumentException("The method or operation is not implemented on this geometry type."); } }