public static IGeometry ReProject(this IGeometry geometry, CoordinateSystemId fromCoordinateSystem, CoordinateSystemId toCoordinateSystem)
        {
            if (geometry == null || fromCoordinateSystem == toCoordinateSystem)
            {
                return(geometry);
            }

            var factory    = new CoordinateTransformationFactory();
            var fromSystem = CoordinateSystemWktReader.Parse(fromCoordinateSystem.GetWkt()) as ICoordinateSystem;
            var toSystem   = CoordinateSystemWktReader.Parse(toCoordinateSystem.GetWkt()) as ICoordinateSystem;

            var transformator = factory.CreateFromCoordinateSystems(fromSystem, toSystem);

            switch (geometry.GeometryType)
            {
            case "MultiPolygon":
                return(((IMultiPolygon)geometry).ReProject(transformator));

            case "Polygon":
                return(((IPolygon)geometry).ReProject(transformator));

            case "LinearRing":
                return(((ILinearRing)geometry).ReProject(transformator));

            case "Point":
                return(((IPoint)geometry).ReProject(transformator));
            }

            return(null);
        }
コード例 #2
0
        public static ICoordinateSystem Read(string fileName, Encoding encoding = null)
        {
            string csStr = encoding == null?File.ReadAllText(fileName, Encoding.Default) : File.ReadAllText(fileName, encoding);

            var cs = (encoding == null ? CoordinateSystemWktReader.Parse(csStr, Encoding.Default) : CoordinateSystemWktReader.Parse(csStr, encoding)) as ICoordinateSystem;

            return(cs);
        }
        public void Filter(GeoAPI.Geometries.Coordinate coord)
        {
            ProjNet.CoordinateSystems.ICoordinateSystem           mercator = getMercatorProjection();
            ProjNet.CoordinateSystems.IGeographicCoordinateSystem latlon   =
                (ProjNet.CoordinateSystems.IGeographicCoordinateSystem)CoordinateSystemWktReader.Parse(SRID_4236);
            ProjNet.CoordinateSystems.Transformations.ICoordinateTransformationFactory ctfac          = new CoordinateTransformationFactory();
            ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation        transformation =
                ctfac.CreateFromCoordinateSystems(latlon, mercator);

            double[] newCoords = transformation.MathTransform.Transform(new double[] { coord.X, coord.Y });
            coord.X = newCoords[0];
            coord.Y = newCoords[1];
        }
コード例 #4
0
        // http://www.sharpgis.net/post/2007/07/27/The-Microsoft-Live-Maps-and-Google-Maps-projection.aspx
        private static ICoordinateTransformation Transform2Mercator2(ICoordinateSystem source)
        {
            string wkt = @"PROJCS[""Mercator Spheric"", GEOGCS[""WGS84basedSpheric_GCS"", DATUM[""WGS84basedSpheric_Datum"", 
        SPHEROID[""WGS84based_Sphere"", 6378137, 0], TOWGS84[0, 0, 0, 0, 0, 0, 0]], PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]], 
        UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], AXIS[""E"", EAST], AXIS[""N"", NORTH]], PROJECTION[""Mercator""], 
        PARAMETER[""False_Easting"", 0], PARAMETER[""False_Northing"", 0], PARAMETER[""Central_Meridian"", 0], PARAMETER[""Latitude_of_origin"", 0],
        UNIT[""metre"", 1, AUTHORITY[""EPSG"", ""9001""]], AXIS[""East"", EAST], AXIS[""North"", NORTH]]";

            CoordinateSystemFactory cFac = new CoordinateSystemFactory();
            ICoordinateSystem       g    = (ICoordinateSystem)CoordinateSystemWktReader.Parse(wkt);;

            return(new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, g));
        }
        /// <summary>
        /// Check that data is valid.
        /// </summary>
        /// <param name="coordinateSystem">This coordinate system.</param>
        public static void CheckData(this WebCoordinateSystem coordinateSystem)
        {
            String wkt;

            coordinateSystem.CheckNotNull("coordinateSystem");
            wkt = coordinateSystem.GetWkt();
            wkt.CheckNotEmpty("coordinateSystem.wkt");
            try
            {
                CoordinateSystemWktReader.Parse(wkt);
            }
            catch
            {
                throw new ArgumentException("Wrong format in coordinate system: " + wkt);
            }
        }