private Boolean RoundTrip(Coordinate p, double tolerance) { _transformCount++; _transForward.Transform(p, _p2); _transInverse.Transform(_p2, _p3); if (_debug) { Console.WriteLine(p + " -> " + _p2 + " -> " + _p3); } double dx = Math.Abs(_p3.X - p.X); double dy = Math.Abs(_p3.Y - p.Y); Boolean isInTol = dx <= tolerance && dy <= tolerance; if (!isInTol) { Console.WriteLine("FAIL: " + p + " -> " + _p2 + " -> " + _p3); } return(isInTol); }
private static Boolean CheckTransform(String csName, double lon, double lat, double expectedX, double expectedY, double tolerance) { CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); CoordinateReferenceSystemFactory csFactory = new CoordinateReferenceSystemFactory(); /* * Create {@link CoordinateReferenceSystem} & CoordinateTransformation. * Normally this would be carried out once and reused for all transformations */ CoordinateReferenceSystem crs = csFactory.CreateFromName(csName); const String wgs84Param = "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"; CoordinateReferenceSystem wgs84 = csFactory.CreateFromParameters("WGS84", wgs84Param); ICoordinateTransform trans = ctFactory.CreateTransform(wgs84, crs); /* * Create input and output points. * These can be constructed once per thread and reused. */ ProjCoordinate p = new ProjCoordinate(); ProjCoordinate p2 = new ProjCoordinate(); p.X = lon; p.Y = lat; /* * Transform point */ trans.Transform(p, p2); return(IsInTolerance(p2, expectedX, expectedY, tolerance)); }
public void TestExplicitTransform() { const String csName1 = "EPSG:32636"; const String csName2 = "EPSG:4326"; CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); CoordinateReferenceSystemFactory csFactory = new CoordinateReferenceSystemFactory(); /* * Create {@link CoordinateReferenceSystem} & CoordinateTransformation. * Normally this would be carried out once and reused for all transformations */ CoordinateReferenceSystem crs1 = csFactory.CreateFromName(csName1); CoordinateReferenceSystem crs2 = csFactory.CreateFromName(csName2); ICoordinateTransform trans = ctFactory.CreateTransform(crs1, crs2); /* * Create input and output points. * These can be constructed once per thread and reused. */ ProjCoordinate p1 = new ProjCoordinate(); ProjCoordinate p2 = new ProjCoordinate(); p1.X = 500000; p1.Y = 4649776.22482; /* * Transform point */ trans.Transform(p1, p2); Assert.IsTrue(IsInTolerance(p2, 33, 42, 0.000001)); }
private double[] calcCoords(double[] point, string type) { Coordinate coordTrg = new Coordinate(); //coordTrg=trans.Transform(new Coordinate(point[0], point[1]), coordTrg as Coordinate); double[] returnPoint = new double[2]; if (type.Equals("reverse")) { coordTrg = trans.Transform(new Coordinate(point[0], point[1]), coordTrg as Coordinate); returnPoint[0] = Math.Round(coordTrg.Y, 2); returnPoint[1] = Math.Round(coordTrg.X, 2); } else { coordTrg = trans.Transform(new Coordinate(point[1], point[0]), coordTrg as Coordinate); returnPoint[0] = Math.Round(coordTrg.X, 10); returnPoint[1] = Math.Round(coordTrg.Y, 10); } return(returnPoint); }