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 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 CRSFactoryTest() { CoordinateReferenceSystemFactory crsFactory = new CoordinateReferenceSystemFactory(); CoordinateReferenceSystem crsSource = crsFactory.CreateFromName("EPSG:4326"); Assert.IsNotNull(crsSource); Assert.AreEqual("EPSG:4326", crsSource.Name); CoordinateReferenceSystem crsTarget = crsFactory.CreateFromParameters("EPSG:3875", "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"); Assert.IsNotNull(crsTarget); Assert.AreEqual("EPSG:3875", crsTarget.Name); BasicCoordinateTransform t = new BasicCoordinateTransform(crsSource, crsTarget); ProjCoordinate prjSrc = new ProjCoordinate(0, 0); ProjCoordinate prjTgt = new ProjCoordinate(); t.Transform(prjSrc, prjTgt); BasicCoordinateTransform t2 = new BasicCoordinateTransform(crsTarget, crsSource); ProjCoordinate prjTgt2 = new ProjCoordinate(); t2.Transform(prjTgt, prjTgt2); Assert.AreEqual(0d, prjSrc.Distance(prjTgt2)); }
// TODO: provide limit on number of items in cache (LRU) /// <summary> /// /// </summary> /// <param name="name"></param> /// <returns></returns> ///<exception cref="UnsupportedParameterException"/> /// <exception cref="InvalidValueException"></exception> ///<exception cref="UnknownAuthorityCodeException"></exception> public CoordinateReferenceSystem CreateFromName(String name) { CoordinateReferenceSystem proj = null;//(CoordinateReferenceSystem) ProjCache.get(name); if (ProjCache.TryGetValue(name, out proj)) { proj = CrsFactory.CreateFromName(name); ProjCache.Add(name, proj); } return(proj); }
public CoordinateReferenceSystem CreateCRS(CoordinateReferenceSystemFactory crsFactory, String auth, String code) { var name = CRSName(auth, code); if (_crsCache != null) { return(_crsCache.CreateFromName(name)); } var cs = crsFactory.CreateFromName(name); return(cs); }
public void testRepeatedTransform() { var crsFactory = new CoordinateReferenceSystemFactory(); var src = crsFactory.CreateFromName("epsg:4326"); var dest = crsFactory.CreateFromName("epsg:27700"); var ctf = new CoordinateTransformFactory(); var transform = ctf.CreateTransform(src, dest); var srcPt = new ProjCoordinate(0.899167, 51.357216); var destPt = new ProjCoordinate(); transform.Transform(srcPt, destPt); Console.WriteLine(srcPt + " ==> " + destPt); // do it again var destPt2 = new ProjCoordinate(); transform.Transform(srcPt, destPt2); Console.WriteLine(srcPt + " ==> " + destPt2); Assert.IsTrue(destPt.Equals(destPt2)); }
private static CoordinateReferenceSystem CreateCRS(String crsSpec) { CoordinateReferenceSystem cs; // test if name is a PROJ4 spec if (crsSpec.IndexOf("+") >= 0) { cs = crsFactory.CreateFromParameters("Anon", crsSpec); } else { cs = crsFactory.CreateFromName(crsSpec); } return(cs); }
static void Run(String code) { CoordinateReferenceSystemFactory csFactory = new CoordinateReferenceSystemFactory(); CoordinateReferenceSystem cs = csFactory.CreateFromName(code); if (cs == null) { return; } ProjectionGridRoundTripper tripper = new ProjectionGridRoundTripper(cs); //tripper.setLevelDebug(true); Boolean isOK = tripper.RunGrid(Tolerance); double[] extent = tripper.Extent; Console.WriteLine(code + " - " + cs.GetParameterString()); Console.WriteLine( @" - extent: [ " + extent[0] + @", " + extent[1] + @" : " + extent[2] + @", " + extent[3] + @" ]" + @" - tol: " + Tolerance + @" - # pts run = " + tripper.TransformCount); Assert.IsTrue(isOK); }