Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        private Boolean ExecuteTransform(
            CoordinateReferenceSystem srcCRS,
            CoordinateReferenceSystem tgtCRS)
        {
            _srcPt.X = _srcOrd1;
            _srcPt.Y = _srcOrd2;
            // Testing: flip axis order to test SS sample file
            // srcPt.x = srcOrd2;
            // srcPt.y = srcOrd1;

            var trans = CtFactory.CreateTransform(srcCRS, tgtCRS);

            trans.Transform(_srcPt, _resultPt);

            var dx = Math.Abs(_resultPt.X - _tgtOrd1);
            var dy = Math.Abs(_resultPt.Y - _tgtOrd2);
            var dz = 0d;

            if (!Double.IsNaN(_tolOrd3))
            {
                dz = Math.Abs(_resultPt.Z - _tgtOrd3);
            }

            _isInTol = dx <= _tolOrd1 && dy <= _tolOrd2;
            if (dz != 0)
            {
                _isInTol |= (!double.IsNaN(dz) && dz <= _tolOrd3);
            }

            return(_isInTol);
        }
Esempio n. 4
0
        public List <string[]> transformCoords(string system, List <string[]> points, string type)
        {
            initRefSystem(system);
            List <string[]> returnList = new List <string[]>();

            if (type.Equals("reverse"))
            {
                trans = ctFac.CreateTransform(geographSystem, selectedSystem);
            }
            else
            {
                trans = ctFac.CreateTransform(selectedSystem, geographSystem);
            }
            NumberFormatInfo nFormatInfo = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();

            nFormatInfo.NumberDecimalSeparator = ",";
            foreach (string[] sPoint in points)
            {
                double[] dPoint   = new double[] { Convert.ToDouble(sPoint[0], nFormatInfo), Convert.ToDouble(sPoint[1], nFormatInfo) };
                double[] newPoint = calcCoords(dPoint, type);
                returnList.Add(new string[] { newPoint[0].ToString(nFormatInfo), newPoint[1].ToString(nFormatInfo) });
            }
            return(returnList);
        }
        public Boolean CheckTransform(
            CoordinateReferenceSystem srcCRS, double x1, double y1,
            CoordinateReferenceSystem tgtCRS, double x2, double y2,
            double tolerance)
        {
            p.X = x1;
            p.Y = y1;
            var trans = ctFactory.CreateTransform(srcCRS, tgtCRS);

            trans.Transform(p, p2);

            var dx    = Math.Abs(p2.X - x2);
            var dy    = Math.Abs(p2.Y - y2);
            var delta = Math.Max(dx, dy);

            if (_verbose)
            {
                Console.Write("{0} => {1}", srcCRS.Name, tgtCRS.Name);
            }

            var isInTol = delta <= tolerance;

            if (_verbose)
            {
                if (!isInTol)
                {
                    Console.WriteLine(" ... FAILED");
                    var source = p.ToShortString();
                    Console.WriteLine("\t{0} -> {1}", source, p2.ToShortString());

                    var result = new ProjCoordinate(x2, y2);
                    var offset = new ProjCoordinate(p2.X - x2, p2.Y - y2);
                    Console.WriteLine("\t{0}    {1},  (tolerance={2}, max delta={3})",
                                      new string(' ', source.Length), result.ToShortString(),
                                      tolerance, delta);
                    Console.WriteLine("\tSource CRS: " + srcCRS.GetParameterString());
                    Console.WriteLine("\tTarget CRS: " + tgtCRS.GetParameterString());
                }
                else
                {
                    Console.WriteLine(" ... PASSED");
                }
            }


            return(isInTol);
        }
        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));
        }
 public ProjectionGridRoundTripper(CoordinateReferenceSystem cs)
 {
     _cs           = cs;
     _transInverse = CtFactory.CreateTransform(cs, WGS84);
     _transForward = CtFactory.CreateTransform(WGS84, cs);
 }