예제 #1
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));
        }
예제 #2
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));
        }
예제 #3
0
        private void onSpatialReferenceChanged()
        {
            _geoFactory = _geoFactory.Clone();
            _geoFactory.SpatialReference = SpatialReference;

            foreach (ILayer layer in _layers)
            {
                if (!layer.SpatialReference.EqualParams(SpatialReference))
                {
                    if (layer.CoordinateTransformation != null)
                    {
                        // TODO: do we ever need to support multiple transforms?
                        throw new InvalidOperationException("The layer already has a coordinate transform.");
                    }

                    layer.CoordinateTransformation
                        = CoordinateTransformFactory.CreateFromCoordinateSystems(layer.SpatialReference,
                                                                                 SpatialReference);
                }
            }

            _extents = null;

            raisePropertyChanged(SpatialReferenceProperty.Name);
        }
        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));
        }