private static bool TestWktWkb(int number, IGeometryFactory factory, string wkt, string wkb) { WKTReader r = new WKTReader(factory); IGeometry wktGeom = r.Read(wkt); WKBReader s = new WKBReader(factory); IGeometry wkbGeom = s.Read(WKBReader.HexToBytes(wkb)); try { Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match"); Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9"); if (!wktGeom.EqualsExact(wkbGeom)) { Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())"); var wktGeom2 = s.Read(wktGeom.AsBinary()); Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())"); var diff = wkbGeom.Difference(wktGeom); Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText()); } return(false); } catch (AssertionException ex) { Console.WriteLine(ex.Message); return(true); } }
public static IGeometry discreteHausdorffDistanceLine(IGeometry a, IGeometry b) { var dist = new DiscreteHausdorffDistance(a, b); dist.Distance(); return(a.Factory.CreateLineString(dist.Coordinates)); }
private static void DoIntersection(Geometry poly1, Geometry poly2, Geometry clip = null) { Assert.IsTrue(poly1.IsValid); Assert.IsTrue(poly1 is Polygon); Assert.IsTrue(poly2.IsValid); Assert.IsTrue(poly2 is Polygon); var intersection = poly1.Intersection(poly2); Assert.IsNotNull(intersection); Assert.IsTrue(intersection.IsValid); var reader = new WKTReader(); var expectedIntersection = reader.Read(ExpectedResult); if (clip != null) { expectedIntersection = expectedIntersection.Intersection(clip); } double hd = DiscreteHausdorffDistance.Distance(intersection, expectedIntersection); Assert.That(hd < 0.001, "Intersection error: result not same as JTS"); }
public static IGeometry densifiedDiscreteHausdorffDistanceLine(IGeometry a, IGeometry b, double frac) { var hausDist = new DiscreteHausdorffDistance(a, b); hausDist.DensifyFraction = frac; hausDist.Distance(); return(a.Factory.CreateLineString(hausDist.Coordinates)); }
private void RunTest(string wkt1, string wkt2, double densifyFrac, double expectedDistance) { var g1 = GeometryUtils.ReadWKT(wkt1); var g2 = GeometryUtils.ReadWKT(wkt2); double distance = DiscreteHausdorffDistance.Distance(g1, g2, densifyFrac); Assert.AreEqual(distance, expectedDistance, TOLERANCE); }
private void RunTest(string wkt1, string wkt2, double expectedDistance) { var g1 = IOUtil.ReadWKT(wkt1); var g2 = IOUtil.ReadWKT(wkt2); double distance = DiscreteHausdorffDistance.Distance(g1, g2); Assert.AreEqual(distance, expectedDistance, TOLERANCE); }
private void RunTest(String wkt1, String wkt2, double expectedDistance) { IGeometry g1 = GeometryUtils.ReadWKT(wkt1); IGeometry g2 = GeometryUtils.ReadWKT(wkt2); double distance = DiscreteHausdorffDistance.Distance(g1, g2); Assert.AreEqual(distance, expectedDistance, TOLERANCE); }
public double Measure(Geometry g1, Geometry g2) { double distance = DiscreteHausdorffDistance.Distance(g1, g2, DensifyFraction); var env = new Envelope(g1.EnvelopeInternal); env.ExpandToInclude(g2.EnvelopeInternal); double envSize = DiagonalSize(env); // normalize so that more similarity produces a measure closer to 1 double measure = 1 - distance / envSize; //System.out.println("Hausdorff distance = " + distance + ", measure = " + measure); return(measure); }
/// <summary> /// Tests encoding/decoding a route. /// </summary> public static void TestEncodeDecoderRoute(Coder coder, Coordinate[] points) { var referencedLine = coder.BuildLine(points); var referencedLineJson = referencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var encoded = coder.Encode(referencedLine); var decodedReferencedLine = coder.Decode(encoded) as ReferencedLine; var decodedReferencedLineJson = decodedReferencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var distance = DiscreteHausdorffDistance.Distance(referencedLine.ToLineString(coder.Router.Db), decodedReferencedLine.ToLineString(coder.Router.Db)); Assert.IsTrue(distance < .1); }
/// <summary> /// Tests encoding/decoding a route. /// </summary> public static void TestEncodeDecoderRoute(Coder coder, Coordinate[] points) { var referencedLine = coder.BuildLine(points); var referencedLineJson = referencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); float positiveOffset, negativeOffset; RouterPoint source, target; var path = referencedLine.BuildPathFromLine(coder.Router.Db, out source, out positiveOffset, out target, out negativeOffset); var route = coder.Router.BuildRoute(coder.Profile.Profile, coder.Router.GetDefaultWeightHandler(coder.Profile.Profile), source, target, path); var encoded = coder.Encode(referencedLine); var decodedReferencedLine = coder.Decode(encoded) as ReferencedLine; var decodedReferencedLineJson = decodedReferencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var distance = DiscreteHausdorffDistance.Distance(referencedLine.ToLineString(coder.Router.Db), decodedReferencedLine.ToLineString(coder.Router.Db)); Assert.IsTrue(distance < .1); }
public static double discreteHausdorffDistance(IGeometry a, IGeometry b) { var dist = new DiscreteHausdorffDistance(a, b); return(dist.Distance()); }