Пример #1
0
        private static IEnumerable <GeoJSON> QueryData(BoundingBox bbox, ICanQueryLayer layer)
        {
            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }

            // Query for data
            FeatureDataSet ds = new FeatureDataSet();

            layer.ExecuteIntersectionQuery(bbox, ds);
            IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(ds);

            // Reproject geometries if needed
            IMathTransform transform = null;

            if (layer is VectorLayer)
            {
                ICoordinateTransformation transformation = (layer as VectorLayer).CoordinateTransformation;
                transform = transformation == null ? null : transformation.MathTransform;
            }
            if (transform != null)
            {
                GeometryFactory gf = new GeometryFactory();
                data = data.Select(d =>
                {
                    Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, gf);
                    d.SetGeometry(converted);
                    return(d);
                });
            }
            return(data);
        }
Пример #2
0
 override public FeatureList process(FeatureList input, FilterEnv env)
 {
     foreach (Feature feature in input)
     {
         CoordinateSystemFactory csf      = new CoordinateSystemFactory();
         ICoordinateSystem       cssource = csf.CreateFromWkt(((SharpMapSpatialReference)feature.getGeometry().SpatialReference).CoordinateSystem.WKT);
         ICoordinateSystem       cstarget;
         if (translateScript != null)
         {
             //Console.WriteLine(Registry.instance().GetEngine("Python").run(TranslateScript).asString());
             cstarget = csf.CreateFromWkt(Registry.instance().GetEngine("Python").run(TranslateScript).asString());
         }
         else
         {
             cstarget = csf.CreateFromWkt(env.getInputSRS().WKT);
         }
         CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();
         ICoordinateTransformation       ct  = ctf.CreateFromCoordinateSystems(cssource, cstarget);
         //if (feature.getGeometry().GeometryType == GeometryType2.Point)
         //{
         //    Point p = (Point)feature.getGeometry();
         //GeometryTransform.TransformPoint(feature, ct.MathTransform);
         Geometry geom    = feature.getGeometry();
         Geometry geomRst = GeometryTransform.TransformGeometry(geom, ct.MathTransform);
         feature.setGeometry(geomRst);
         //}
     }
     return(input);
 }
Пример #3
0
 public void TestConversion()
 {
     var point     = GeometryFactory.Default.CreatePoint(new Coordinate(492155.73, 6303867.82));
     var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(
         ProjectedCoordinateSystem.WGS84_UTM(32, true), GeographicCoordinateSystem.WGS84);
     var transformedPoint = GeometryTransform.TransformGeometry(GeometryFactory.Default, point, transform.MathTransform);
 }
Пример #4
0
        protected virtual IGeometry ToSource(IGeometry geometry)
        {
            if (geometry.SRID == SRID)
            {
                return(geometry);
            }

#if !DotSpatialProjections
            if (ReverseCoordinateTransformation != null)
            {
                return(GeometryTransform.TransformGeometry(geometry,
                                                           ReverseCoordinateTransformation.MathTransform, SourceFactory));
            }
#endif
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                var mt = CoordinateTransformation.MathTransform;
                mt.Invert();
                var res = GeometryTransform.TransformGeometry(geometry, mt, SourceFactory);
                mt.Invert();
                return(res);
#else
                return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source, SourceFactory));
#endif
            }

            return(geometry);
        }
        public static IGeometry ProjectTo(this IGeometry geometry, int srid)
        {
            var geometryFactory = _geometryServices.CreateGeometryFactory(srid);
            var transformation  = _coordinateSystemServices.CreateTransformation(geometry.SRID, srid);

            return(GeometryTransform.TransformGeometry(geometryFactory, geometry, transformation.MathTransform));
        }
Пример #6
0
        public static Point WgsToGoogle(Point p)
        {
            GeometryFactory factory = new NetTopologySuite.Geometries.GeometryFactory();
            Point           result  = GeometryTransform.TransformGeometry(p, LayerTools.wgs84toGoogle.MathTransform, factory) as Point;

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Geometry geometry, FeatureDataSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform);
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform);
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                _dataSource.Close();
            }
        }
        public static IGeometry ToSource(this Layer self, IGeometry geometry, IGeometryFactory sourceFactory)
        {
            if (geometry.SRID == sourceFactory.SRID)
            {
                return(geometry);
            }

#if !DotSpatialProjections
            if (self.ReverseCoordinateTransformation != null)
            {
                return(GeometryTransform.TransformGeometry(geometry,
                                                           self.ReverseCoordinateTransformation.MathTransform, sourceFactory));
            }
#endif
            if (self.CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                var mt = self.CoordinateTransformation.MathTransform;
                mt.Invert();
                var res = GeometryTransform.TransformGeometry(geometry, mt, sourceFactory);
                mt.Invert();
                return(res);
#else
                return(GeometryTransform.TransformGeometry(geometry,
                                                           self.CoordinateTransformation.Target,
                                                           self.CoordinateTransformation.Source, SourceFactory));
#endif
            }

            return(geometry);
        }
Пример #9
0
        public static Point GoogleToWgs(Point p)
        {
            GeometryFactory factory = new NetTopologySuite.Geometries.GeometryFactory();
            Point           result  = GeometryTransform.TransformGeometry(p, LayerTools.GoogleMercatorToWgs84.MathTransform, factory) as Point;

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Find the nearest feature to worldPos out of a collection of candidates. If there is no geometry
        /// with a distance less than limit null is returned.
        /// </summary>
        /// <param name="candidates"></param>
        /// <param name="worldPos"></param>
        /// <param name="limit"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        private static IFeature FindNearestFeature(VectorLayer vectorLayer, IEnumerable candidates, ICoordinate worldPos,
                                                   float limit, out double distance)
        {
            IPoint point = GeometryFactory.CreatePoint(worldPos.X, worldPos.Y);

            IFeature current = null;

            distance = double.MaxValue;
            foreach (IFeature feature in candidates)
            {
                IGeometry geometry;
                if (vectorLayer.CustomRenderers.Count > 0)
                {
                    geometry = vectorLayer.CustomRenderers[0].GetRenderedFeatureGeometry(feature, vectorLayer);
                }
                else
                {
                    if (vectorLayer.CoordinateTransformation != null)
                    {
                        geometry = GeometryTransform.TransformGeometry(feature.Geometry, vectorLayer.CoordinateTransformation.MathTransform);
                    }
                    else
                    {
                        geometry = feature.Geometry;
                    }
                }
                double localDistance = geometry.Distance(point);
                if ((localDistance < distance) && (localDistance < limit))
                {
                    current  = feature;
                    distance = localDistance;
                }
            }
            return(current);
        }
Пример #11
0
        private IGeometry TransformGeo(IGeometry g)
        {
            Geometry geo = (Geometry)g;

#if DDOT
            string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]";
            CoordinateSystemFactory cFacWGS = new CoordinateSystemFactory();
            ICoordinateSystem       wgs84   = cFacWGS.CreateFromWkt(wkt);

            //
            // Acquire the state plane project from
            // http://spatialreference.org/
            //wkt = "PROJCS[\"NAD_1983_StatePlane_Maryland_FIPS_1900_Meter\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",1312333.333333333],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-77],PARAMETER[\"Standard_Parallel_1\",38.3],PARAMETER[\"Standard_Parallel_2\",39.45],PARAMETER[\"Latitude_Of_Origin\",37.66666666666666],UNIT[\"Foot_US\",0.30480060960121924]]";
            //wkt = "PROJCS["NAD_1983_StatePlane_Florida_West_FIPS_0902_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",656166.6666666665],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",-82],PARAMETER["Scale_Factor",0.9999411764705882],PARAMETER["Latitude_Of_Origin",24.33333333333333],UNIT["Foot_US",0.30480060960121924]]"
            wkt = "PROJCS[\"NAD_1983_StatePlane_Maryland_FIPS_1900_Meter\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",399999.2],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-77],PARAMETER[\"Standard_Parallel_1\",38.3],PARAMETER[\"Standard_Parallel_2\",39.45],PARAMETER[\"Latitude_Of_Origin\",37.66666666666666],UNIT[\"Meter\",1]]";
            //wkt = "PROJCS[\"GRS_1980_Transverse_Mercator\",GEOGCS[\"GCS_GRS_1980\",DATUM[\"D_GRS_1980\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"Scale_Factor\",1.00005000],PARAMETER[\"False_Easting\",164041.66666667],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-96.68805556],PARAMETER[\"Latitude_Of_Origin\",40.25000000],UNIT[\"Foot_US\",0.30480060960121924]]";
            CoordinateSystemFactory cFac1 = new CoordinateSystemFactory();
            ICoordinateSystem       nad83 = cFac1.CreateFromWkt(wkt);


            CoordinateTransformationFactory ctFac      = new CoordinateTransformationFactory();
            ICoordinateTransformation       transDeg2M = ctFac.CreateFromCoordinateSystems(nad83, wgs84); //Geocentric->Geographic (WGS84)
            geo = GeometryTransform.TransformGeometry((Geometry)g, transDeg2M.MathTransform);
#endif
            return(geo);
        }
Пример #12
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, FeatureDataSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)ReverseCoordinateTransformation.TargetCS.AuthorityCode));
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode));
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry,
                                                               CoordinateTransformation.Target,
                                                               CoordinateTransformation.Source,
                                                               CoordinateTransformation.SourceFactory);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                _dataSource.Close();
            }
        }
Пример #13
0
        private IGeometry TransformSingleGeometry(IGeometry g)
        {
            CoordinateTransformationFactory ctFac      = new CoordinateTransformationFactory();
            ICoordinateTransformation       transDeg2M = ctFac.CreateFromCoordinateSystems(nad83, wgs84); //Geocentric->Geographic (WGS84)
            Geometry geo = GeometryTransform.TransformGeometry((Geometry)g, transDeg2M.MathTransform);

            return(geo);
        }
Пример #14
0
        public void TestGeometryCollection()
        {
            const string wkt = "GEOMETRYCOLLECTION (POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200)), LINESTRING (250 100, 350 200), POINT (350 150))";
            var          g1  = (IGeometryCollection)_reader.Read(wkt);
            var          g2  = (IGeometryCollection)GeometryTransform.TransformGeometry(_factory, g1,
                                                                                        _mathTransform);

            TestGeometry(g1, g2);
        }
Пример #15
0
        public void TestPolygon()
        {
            const string wkt = "POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))";
            var          g1  = (IPolygon)_reader.Read(wkt);
            var          g2  = (IPolygon)GeometryTransform.TransformGeometry(_factory, g1,
                                                                             _mathTransform);

            TestGeometry(g1, g2);
        }
Пример #16
0
        public void TestPoint()
        {
            const string wkt = "POINT ( 10 20 )";
            var          g1  = (IPoint)_reader.Read(wkt);
            var          g2  = (IPoint)GeometryTransform.TransformGeometry(_factory, g1,
                                                                           _mathTransform);

            TestGeometry(g1, g2);
        }
Пример #17
0
        public void TestLineString()
        {
            const string wkt = "LINESTRING(0 0, 10 10)";
            var          g1  = (ILineString)_reader.Read(wkt);
            var          g2  = (ILineString)GeometryTransform.TransformGeometry(_factory, g1,
                                                                                _mathTransform);

            TestGeometry(g1, g2);
        }
Пример #18
0
        protected void RenderInternal(Graphics g, Map map, BoundingBox envelope, RenderType rendertype)
        {
            if (!Style.Enabled)
            {
                return;
            }

            VectorStyle           vStyle = Style.Clone();
            Collection <Geometry> geoms;

            lock (_dataSource)
            {
                bool alreadyOpen = DataSource.IsOpen;

                if (!alreadyOpen)
                {
                    DataSource.Open();
                }

                geoms = DataSource.GetGeometriesInView(envelope);
                Console.Out.WriteLine(string.Format("Layer {0}, NumGeometries {1}", LayerName, geoms.Count));

                if (!alreadyOpen)
                {
                    DataSource.Close();
                }
            }
            if (CoordinateTransformation != null)
            {
                for (int i = 0; i < geoms.Count; i++)
#if !DotSpatialProjections
                { geoms[i] = GeometryTransform.TransformGeometry(geoms[i], CoordinateTransformation.MathTransform); }
            }
#else
                { geoms[i] = GeometryTransform.TransformGeometry(geoms[i], CoordinateTransformation.Source, CoordinateTransformation.Target); }
#endif
            if (vStyle.LineSymbolizer != null)
            {
                vStyle.LineSymbolizer.Begin(g, map, geoms.Count);
            }
            VectorRenderer.width = vStyle.Outline.Width;
            for (int i = 0; i < geoms.Count; i++)
            {
                if (geoms[i] != null)
                {
                    RenderGeometry(g, map, geoms[i], vStyle, rendertype);
                }
            }

            if (vStyle.LineSymbolizer != null)
            {
                vStyle.LineSymbolizer.Symbolize(g, map);
                vStyle.LineSymbolizer.End(g, map);
            }
        }
Пример #19
0
        protected IGeometry ToTarget(IGeometry geometry)
        {
            if (CoordinateTransformation == null)
            {
                return(geometry);
            }
#if !DotSpatialProjections
            return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, geometry.Factory));
#else
            return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Source, CoordinateTransformation.Target, targetFactory));
#endif
        }
Пример #20
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 ///
 /// Note! The table added should be named according to the LayerName!
 /// </summary>
 /// <param name="geometry">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(IGeometry geometry, FeatureDataSet ds)
 {
     if (CoordinateTransformation != null)
     {
         geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform.Inverse(), geometry.Factory);
     }
     DataSource.ExecuteIntersectionQuery(geometry, ds);
     if (ds.Tables.Count > 0)
     {
         ds.Tables[0].TableName = LayerName;
     }
 }
Пример #21
0
        protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map,
                                                                            IEnumerable <string> requestedLayers,
                                                                            float x, float y,
                                                                            int featureCount,
                                                                            string cqlFilter,
                                                                            int pixelSensitivity,
                                                                            WmsServer.InterSectDelegate intersectDelegate)
        {
            List <GeoJSON> items = new List <GeoJSON>();

            foreach (string requestLayer in requestedLayers)
            {
                ICanQueryLayer queryLayer = GetQueryLayer(map, requestLayer);
                FeatureDataSet fds;
                if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, queryLayer, cqlFilter, out fds))
                {
                    continue;
                }

                IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(fds);
                // reproject geometries if needed
                IMathTransform transform = null;
                if (queryLayer is VectorLayer)
                {
                    ICoordinateTransformation transformation = (queryLayer as VectorLayer).CoordinateTransformation;
                    if (transformation != null)
                    {
                        transform = transformation.MathTransform;
                    }
                }

                if (transform != null)
                {
#if DotSpatialProjections
                    throw new NotImplementedException();
#else
                    data = data.Select(d =>
                    {
                        IGeometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, map.Factory);
                        d.SetGeometry(converted);
                        return(d);
                    });
#endif
                }
                items.AddRange(data);
            }

            StringWriter sb = new StringWriter();
            GeoJSONWriter.Write(items, sb);
            return(new GetFeatureInfoResponseJson(sb.ToString()));
        }
Пример #22
0
        protected virtual IGeometry ToTarget(IGeometry geometry)
        {
            if (geometry.SRID == TargetSRID)
            {
                return(geometry);
            }

            if (CoordinateTransformation != null)
            {
                return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, TargetFactory));
            }

            return(geometry);
        }
Пример #23
0
        override public FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            //resolve the xlate shortcut
            Mogre.Matrix4 workingMatrix = Matrix;

            //TODO: this can go into process (FeatureList) instead of running for every feature..
            if (TranslateScript != null)
            {
                ScriptResult r = env.getScriptEngine().run(TranslateScript, input, env);
                if (r.isValid())
                {
                    workingMatrix.MakeTrans(new Mogre.Vector3((float)r.asVec3().x, (float)r.asVec3().y, (float)r.asVec3().z));
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
            if (workingSrs != null || (workingMatrix != null && workingMatrix != Mogre.Matrix4.IDENTITY))
            {
                //TODO foreach (Geometry shape in input.getGeometry())
                //{
                //    if (workingMatrix != null && !workingMatrix.Equals(Mogre.Matrix4.IDENTITY))
                //    {

                //        XformVisitor visitor = new XformVisitor();
                //        visitor.mat = workingMatrix;
                //        shape.accept(visitor);
                //    }
                //    if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                //    {
                //        workingSrs.transformInPlace(shape);
                //    }
                //}
                if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                {
                    Geometry temp = GeometryTransform.TransformGeometry(input.getGeometry(), ((SharpMapSpatialReference)workingSrs).MathTransform);
                    input.setGeometry(temp);
                    //workingSrs.transformInPlace(input.getGeometry());
                }
            }
            output.Add(input);
            return(output);
        }
Пример #24
0
        protected virtual IGeometry ToTarget(IGeometry geometry)
        {
            if (geometry.SRID == EarthSrid || (geometry.SRID <= 0 && CoordinateTransformation == null))
            {
                return(geometry);
            }

            if (CoordinateTransformation == null || geometry.SRID != CoordinateTransformation.SourceCS.AuthorityCode)
            {
                var sourceCs = SharpMap.Session.Instance.CoordinateSystemServices.GetCoordinateSystem(geometry.SRID);

                CoordinateTransformation = SharpMap.Session.Instance.CoordinateSystemServices.CreateTransformation(
                    sourceCs,
                    _earthCs);
            }

            return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, _earthGeometryFactory));
        }
        public void ConvertAPointUsingNetTopologySuiteTransformGeometry()
        {
            //SETUP
            var factory      = NetTopologySuite.Geometries.GeometryFactory.Default;
            var pointNatGrid = new NetTopologySuite.Geometries.Point(532248.29992272425, 181560.30052819476);

            //ATTEMPT
            var transform = new DotSpatialMathTransform(
                _britishNationalGridOsgb36, _wgs84);
            var result = GeometryTransform.TransformGeometry(
                factory, pointNatGrid, transform);

            //VERIFY
            Assert.AreEqual("Point", result.GeometryType);
            Assert.AreEqual(1, result.Coordinates.Length);
            Assert.AreEqual(-0.095399303, result.Coordinate.X, 0.001);
            Assert.AreEqual(51.517489, result.Coordinates[0].Y, 0.001);
        }
Пример #26
0
        protected virtual IGeometry ToTarget(IGeometry geometry)
        {
            if (geometry.SRID == TargetSRID)
            {
                return(geometry);
            }

            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, TargetFactory));
#else
                return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Source, CoordinateTransformation.Target, TargetFactory));
#endif
            }

            return(geometry);
        }
        protected virtual IGeometry ToTarget(IGeometry geometry)
        {
            if (geometry.SRID == EarthSrid || (geometry.SRID <= 0 && CoordinateTransformation == null))
            {
                return(geometry);
            }

            if (CoordinateTransformation == null || geometry.SRID != CoordinateTransformation.SourceCS.AuthorityCode)
            {
                var sourceWkt = SpatialReference.SridToWkt(geometry.SRID);
                var sourceCs  = CoordinateSystemFactory.CreateFromWkt(sourceWkt);

                CoordinateTransformation = CoordinateTransformationFactory.CreateFromCoordinateSystems(
                    sourceCs,
                    _earthCs);
            }

            return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, _earthGeometryFactory));
        }
        public static IGeometry ToTarget(this Layer self, IGeometry geometry, IGeometryFactory targetFactory)
        {
            if (geometry.SRID == self.TargetSRID)
            {
                return(geometry);
            }

            if (self.CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                return(GeometryTransform.TransformGeometry(geometry, self.CoordinateTransformation.MathTransform, targetFactory));
#else
                return(GeometryTransform.TransformGeometry(geometry,
                                                           self.CoordinateTransformation.Source,
                                                           self.CoordinateTransformation.Target, TargetFactory));
#endif
            }

            return(geometry);
        }
Пример #29
0
 private void SynchronizeTrackers()
 {
     trackers.Clear();
     foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors)
     {
         foreach (TrackerFeature trackerFeature in featureInteractor.Trackers)
         {
             if (featureInteractor.Layer.CoordinateTransformation != null)
             {
                 var trackerFeature2 = (TrackerFeature)trackerFeature.Clone();
                 trackerFeature2.Geometry = GeometryTransform.TransformGeometry(trackerFeature.Geometry, featureInteractor.Layer.CoordinateTransformation.MathTransform);
                 trackers.Add(trackerFeature2);
             }
             else
             {
                 trackers.Add(trackerFeature);
             }
         }
     }
     trackingLayer.RenderRequired = true;
 }
Пример #30
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.TargetCS.AuthorityCode));
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode));
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry,
                                                               CoordinateTransformation.Target,
                                                               CoordinateTransformation.Source,
                                                               CoordinateTransformation.SourceFactory);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                int tableCount = ds.Count;
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                if (ds.Count > tableCount)
                {
                    //We added a table, name it according to layer
                    var table = ds[ds.Count - 1];
                    table.Name = LayerName;
                }
                _dataSource.Close();
            }
        }