private static ICoordinateTransformation GetCartesianTransform(ref ReferenceOriginWgs84Point referenceOrigin) { if (referenceOrigin == null) { throw new ArgumentException("reference origin point must have value"); } var csFactory = new CoordinateSystemFactory(); var projectionParameters = new List <ProjectionParameter> { new ProjectionParameter("latitude_of_origin", referenceOrigin.Lat), new ProjectionParameter("central_meridian", referenceOrigin.Lon), new ProjectionParameter("false_easting", 0), new ProjectionParameter("false_northing", 0) }; var projection = csFactory.CreateProjection("Mercator_1SP", "Mercator", projectionParameters); IProjectedCoordinateSystem projectedCoordinateSystem = csFactory.CreateProjectedCoordinateSystem("My WGS84", GeographicCoordinateSystem.WGS84, projection, LinearUnit.Metre, new AxisInfo("E", AxisOrientationEnum.East), new AxisInfo("N", AxisOrientationEnum.North)); referenceOrigin.ProjectedCoordinateSystem = projectedCoordinateSystem; var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var transform = ctFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, projectedCoordinateSystem); var transformedPoint = transform.MathTransform.Transform(new[] { referenceOrigin.Lon, referenceOrigin.Lat }); var shift = transformedPoint[1] * -1; referenceOrigin.ShiftedY = shift; return(transform); }
public static GisPoint ConvertToMercatore(GisPoint point) { NetTopologySuite.Geometries.PrecisionModel precisionModel = new NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating); CoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84 as CoordinateSystem; CoordinateSystem mercatore = ProjectedCoordinateSystem.WebMercator as CoordinateSystem; ICoordinateSystemFactory cFac = new CoordinateSystemFactory(); int SRID_wgs84 = Convert.ToInt32(wgs84.AuthorityCode); //WGS84 SRID int SRID_mercatore = Convert.ToInt32(mercatore.AuthorityCode); //Mercatore SRID ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, mercatore); NetTopologySuite.Geometries.GeometryFactory factory_wgs84 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_wgs84); var convertedPoint = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(point.X, point.Y, 0)); double[] coords = transformation.MathTransform.Transform(new double[] { convertedPoint.X, convertedPoint.Y }); NetTopologySuite.Geometries.GeometryFactory factory_mercatore = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_mercatore); var p1 = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords[0], coords[1])); return new GisPoint(p1.X, p1.Y); }
public static double DistanceMeters(Coordinate left, Coordinate right) { const string wkt4326 = "PARAM_MT[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; var transformer = ProjNet.IO.CoordinateSystems.CoordinateSystemWktReader.Parse(wkt4326); //var (x1,y1) = transformer.Transform(left.X, left.Y); //var (x2,y2) = transformer.Transform(right.X, right.Y); //var c1 = new Coordinate(x1, y1); //var c2 = new Coordinate(x2, y2); //var other2 = c1.Distance(c2); var csWgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var cs27700 = ProjNet.IO.CoordinateSystems.CoordinateSystemWktReader.Parse(wkt4326);; var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctFactory.CreateFromCoordinateSystems(csWgs84, new CoordinateSystemFactory() { }.CreateFromWkt(wkt4326)); //var mt = ct.MathTransform; var geometryFactory = NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326); var a = geometryFactory.CreatePoint(left); var b = geometryFactory.CreatePoint(right); var other = a.Distance(b); var distance = DistanceMeters(left.Y, left.X, right.Y, right.X); return(distance); }
private GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation CreateTransformation() { var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); return ctf.CreateFromCoordinateSystems( ProjNet.CoordinateSystems.GeocentricCoordinateSystem.WGS84, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); }
public static Extent ConvertToMercatore(Extent extent) { NetTopologySuite.Geometries.PrecisionModel precisionModel = new NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating); CoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84 as CoordinateSystem; CoordinateSystem mercatore = ProjectedCoordinateSystem.WebMercator as CoordinateSystem; ICoordinateSystemFactory cFac = new CoordinateSystemFactory(); int SRID_wgs84 = Convert.ToInt32(wgs84.AuthorityCode); //WGS84 SRID int SRID_mercatore = Convert.ToInt32(mercatore.AuthorityCode); //Mercatore SRID ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, mercatore); NetTopologySuite.Geometries.GeometryFactory factory_wgs84 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_wgs84); var bottomLeft = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(extent.Left, extent.Bottom, 0)); var topRight = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(extent.Right, extent.Top, 0)); double[] coords_bl = transformation.MathTransform.Transform(new double[] { bottomLeft.X, bottomLeft.Y }); double[] coords_tr = transformation.MathTransform.Transform(new double[] { topRight.X, topRight.Y }); NetTopologySuite.Geometries.GeometryFactory factory_mercatore = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_mercatore); var p1_bl = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_bl[0], coords_bl[1])); var p2_tr = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_tr[0], coords_tr[1])); return new Extent(p1_bl.X, p1_bl.Y, p2_tr.X, p2_tr.Y); }
private void AddShapeLayer_OnClick(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "Shapefiles (*.shp)|*.shp"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var ds = new SharpMap.Data.Providers.ShapeFile(ofd.FileName); var lay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(ofd.FileName), ds); if (ds.CoordinateSystem != null) { GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory fact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); lay.CoordinateTransformation = fact.CreateFromCoordinateSystems(ds.CoordinateSystem, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); lay.ReverseCoordinateTransformation = fact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ds.CoordinateSystem); } WpfMap.MapLayers.Add(lay); if (WpfMap.MapLayers.Count == 1) { Envelope env = lay.Envelope; WpfMap.ZoomToEnvelope(env); } } e.Handled = true; }
private GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation CreateTransformation() { var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); return(ctf.CreateFromCoordinateSystems( ProjNet.CoordinateSystems.GeocentricCoordinateSystem.WGS84, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84)); }
public static void Main(string[] args) { var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); _trans = ctFact.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(33, true), GeographicCoordinateSystem.WGS84); var naturområdeTyper = ReadAll <NaturområdeType>("NaturområdeType"); var beskrivelsesVariabler = ReadAll <Beskrivelsesvariabel>("Beskrivelsesvariabel"); var rødlistekategori = ReadAll <Rødlistekategori>("Rødlistekategori"); var kategoriSet = ReadAll <KategoriSet>("KategoriSet"); var rødlisteVurderingsenhetSet = ReadAll <RødlisteVurderingsenhetSet>("RødlisteVurderingsenhetSet"); var geometries = ReadGeometries(); var root = new root(); var i = 0; Parallel.ForEach(geometries, naturområde => { Interlocked.Increment(ref i); if (naturområdeTyper.All(n => n.Naturområde_id != naturområde.Id) && beskrivelsesVariabler.All(b => b.Naturområde_id != naturområde.Id)) { return; } try { var flexible = GenerateFlexible(naturområde); AddBeskrivelsesVariabler(beskrivelsesVariabler, flexible); AddNaturområdeTyper(naturområdeTyper, flexible); AddRødlistekategori(rødlisteVurderingsenhetSet, rødlistekategori, kategoriSet, flexible); root.features.Add(flexible); } catch (Exception e) { Console.Write("ERROR: Id " + naturområde.Id + ". " + e.Message); Console.WriteLine(); return; } if (i % 100 == 0 && i != 0) { Console.Write("\r{0}% ", (int)(1.0 * i / geometries.Count * 100)); } }); var json = JsonConvert.SerializeObject(root); File.WriteAllText(@"c:\tmp\naturomrader9.json", json); }
private static GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation GetCoordinateTransformation() { //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"); var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], 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], AUTHORITY[\"EPSG\",\"3857\"]]"); return(ctf.CreateFromCoordinateSystems(epsg4326, epsg3857));
private static IGeometry Project(IGeometry geomIn, string zone) { ICoordinateSystem csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326) as ICoordinateSystem; ICoordinateSystem csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(zone) as ICoordinateSystem; ICoordinateTransformation trans = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); IGeometry geomOut = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, geomIn, trans.MathTransform); return(geomOut); }
public static IPoint UnprojectPoint(IPoint p, string zone) { ICoordinateSystem csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(zone) as ICoordinateSystem; ICoordinateSystem csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326) as ICoordinateSystem; ICoordinateTransformation trans = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); IPoint pOut = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformPoint(GeometryFactory.Default, p, trans.MathTransform); return(pOut); }
public AbstractWktCoordinateTransformation(string fromWkt, string toWkt) { this.FromWkt = fromWkt; this.ToWkt = toWkt; this.FromCrs = CoordinateSystemWktReader.Parse(fromWkt, Encoding.ASCII) as ICoordinateSystem; this.ToCrs = CoordinateSystemWktReader.Parse(toWkt, Encoding.ASCII) as ICoordinateSystem; var factory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); this.InternalCoordinateTransformation = factory.CreateFromCoordinateSystems(this.FromCrs, this.ToCrs); }
/// <summary> /// Reprojects a Placeful Polygon to a NetTopologySuite Polygon in a target Coordinate System /// </summary> public NetTopologySuite.Geometries.Polygon Reproject(ProjNet.CoordinateSystems.CoordinateSystem targetProjection) { CoordinateSystemFactory coordSystem = new CoordinateSystemFactory(); var transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var reproject = transform.CreateFromCoordinateSystems(this.CoordinateReferenceSystem, targetProjection); var reprojectedCoords = reproject.MathTransform.TransformList(this.GetCoordinates()); var reprojectedRing = new LinearRing(reprojectedCoords.ToArray()); return(new NetTopologySuite.Geometries.Polygon(reprojectedRing)); }
public void TestConversionProjNet() { var csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var cs1 = csf.CreateFromWkt(Osgb36); var cs2 = csf.CreateFromWkt(WGS84); var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctf.CreateFromCoordinateSystems(cs1, cs2); System.Diagnostics.Debug.Assert(ct != null); }
public void TestConversionProjNet() { var csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var cs1 = csf.CreateFromWkt(Osgb36); var cs2 = csf.CreateFromWkt(WGS84); var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctf.CreateFromCoordinateSystems(cs1, cs2); System.Diagnostics.Debug.Assert(ct != null); }
public static void ConvertEPSG3857_to_SVY21(double lat, double lng, out double[] xy) { var gcs_WGS84 = GeographicCoordinateSystem.WGS84; var coordFactory = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var coordTransform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var svy21 = coordFactory.CreateFromWkt(wkt_SVY21); var transformTo3857 = coordTransform.CreateFromCoordinateSystems(gcs_WGS84, svy21); double[] fromPoint = { lat, lng }; xy = transformTo3857.MathTransform.Transform(fromPoint); }
public static void ConvertSVY21_to_EPSG3857(double x, double y, out double[] lnglat) { var gcs_WGS84 = GeographicCoordinateSystem.WGS84; var coordFactory = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var coordTransform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var svy21 = coordFactory.CreateFromWkt(wkt_SVY21); var transformTo3857 = coordTransform.CreateFromCoordinateSystems(svy21, gcs_WGS84); double[] fromPoint = { x, y }; lnglat = transformTo3857.MathTransform.Transform(fromPoint); }
private static ICoordinateTransformation GetInverseTransform(ref ReferenceOriginWgs84Point referenceOrigin) { if (referenceOrigin.ProjectedCoordinateSystem == null) { GetCartesianTransform(ref referenceOrigin); } var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); return(ctFactory.CreateFromCoordinateSystems(referenceOrigin.ProjectedCoordinateSystem, GeographicCoordinateSystem.WGS84)); }
/// <summary> /// Reprojects a GeoPoint to a NetTopologySuite Point in a target Coordinate System /// </summary> public NetTopologySuite.Geometries.Point Reproject(ProjNet.CoordinateSystems.CoordinateSystem targetProjection) { CoordinateSystemFactory coordSystem = new CoordinateSystemFactory(); var transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var reproject = transform.CreateFromCoordinateSystems(this.CoordinateReferenceSystem, targetProjection); var reprojectedPoint = reproject.MathTransform.Transform(new double[2] { this.GeoCoordinate.X, this.GeoCoordinate.Y }); var reprojectedCoord = new GeoAPI.Geometries.Coordinate(reprojectedPoint[0], reprojectedPoint[1]); return(new NetTopologySuite.Geometries.Point(reprojectedCoord)); }
public static double CalculateM2Area(IGeometry geomIn) { //4326 a 3857 // http://spatialreference.org/ref/esri/south-america-albers-equal-area-conic/ ICoordinateSystem csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326) as ICoordinateSystem; ICoordinateSystem csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(albers2) as ICoordinateSystem; ICoordinateTransformation trans = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); IGeometry geomOut = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, geomIn, trans.MathTransform); return(geomOut.Area); }
private void ToLatLong() { string source_wkt = @"PROJCS[""NAD_1983_HARN_StatePlane_Florida_East_FIPS_0901_Feet"",GEOGCS[""GCS_North_American_1983_HARN"",DATUM[""NAD83_High_Accuracy_Regional_Network"",SPHEROID[""GRS_1980"",6378137.0,298.257222101]],PRIMEM[""Greenwich"",0.0],UNIT[""Degree"",0.0174532925199433]],PROJECTION[""Transverse_Mercator""],PARAMETER[""False_Easting"",656166.6666666665],PARAMETER[""False_Northing"",0.0],PARAMETER[""Central_Meridian"",-81.0],PARAMETER[""Scale_Factor"",0.9999411764705882],PARAMETER[""Latitude_Of_Origin"",24.33333333333333],UNIT[""Foot_US"",0.3048006096012192]]"; var x = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var csource = x.CreateFromWkt(source_wkt); var ctarget = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var t = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = t.CreateFromCoordinateSystems(csource, ctarget); double[] point = { X, Y }; double[] convpoint = trans.MathTransform.Transform(point); Longitude = convpoint[0]; Latitude = convpoint[1]; }
public void TestRealData() { var fdt = GetRealFeatureDataTable(); FillRealDataTable(fdt); var p = new SharpMap.Data.Providers.FeatureProvider(fdt); var m = new SharpMap.Map(new Size(640, 640)); m.Layers.Add(new TileLayer( new OsmTileSource(new OsmRequest(KnownTileServers.Mapnik) /*, new FileCache(@"d:\temp\OSM", "png")*/), "OSM")); var l = new HeatLayer(p, "Data", 0.001f); l.LayerName = "HEAT"; m.Layers.Add(l); #if DotSpatialProjections l.CoordinateTransformation = new DotSpatial.Projections.CoordinateTransformation { Source = ProjectionInfo.FromEpsgCode(4326), Target = ProjectionInfo.FromEpsgCode(3857) }; #else var ctfac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctfac.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); #endif l.ZoomMin = 0;// 0.01 * m.GetExtents().Width; l.ZoomMax = /*0.9 * */m.GetExtents().Width; l.OpacityMax = 1; l.OpacityMin = 0.3f; m.ZoomToBox(l.Envelope); for (var i = 0; i < 5; i++) { using (var img = m.GetMap()) { img.Save("RealDataHeat" + i + ".png"); } m.Zoom /= 2; } m.ZoomToExtents(); using (var img = m.GetMap()) { img.Save("RealDataHeat.png"); } }
public static SharpMap.Map InitializeMap(float angle) { var fdt = GetRealFeatureDataTable(); FillRealDataTable(fdt); var p = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var m = new SharpMap.Map(); m.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer( new BruTile.Web.OsmTileSource( new BruTile.Web.OsmRequest(KnownTileSource.OpenStreetMap), new BruTile.Cache.FileCache(@"d:\temp\OSM", "png")), "OSM")); m.BackgroundLayer[0].LayerName = "TileLayer with HeatLayer"; //var l = new SharpMap.Layers.HeatLayer(p, r => 0.02f) { LayerName = "HEAT" }; var l = new SharpMap.Layers.HeatLayer(p, "Data", 0.00025f) { LayerName = "HEAT" }; m.Layers.Add(l); #if DotSpatialProjections l.CoordinateTransformation = new DotSpatial.Projections.CoordinateTransformation { Source = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(4326), Target = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(3857) }; #else var ctfac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctfac.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); #endif l.ZoomMin = 0;// 0.01 * m.GetExtents().Width; l.ZoomMax = /*0.9 * */m.GetExtents().Width; l.OpacityMax = 0.5f; l.OpacityMin = 0.9f; l.HeatColorBlend = SharpMap.Layers.HeatLayer.Classic; var env = l.Envelope; GeoAPI.Geometries.GeoAPIEx.Grow(env, env.Width * 0.05, env.Height * 0.05); //m.EnforceMaximumExtents = true; //m.MaximumExtents = env; m.ZoomToBox(env); return m; }
public static SharpMap.Map InitializeMap(float angle) { var fdt = GetRealFeatureDataTable(); FillRealDataTable(fdt); var p = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var m = new SharpMap.Map(); var tl = new SharpMap.Layers.TileAsyncLayer(KnownTileSources.Create(KnownTileSource.OpenStreetMap), "TileLayer with HeatLayer", System.Drawing.Color.Transparent, false, new BruTile.Cache.FileCache(@"d:\temp\OSM", "png"), System.Drawing.Imaging.ImageFormat.Png); m.BackgroundLayer.Add(tl); //var l = new SharpMap.Layers.HeatLayer(p, r => 0.02f) { LayerName = "HEAT" }; var l = new SharpMap.Layers.HeatLayer(p, "Data", 0.00025f) { LayerName = "HEAT" }; m.Layers.Add(l); var ctfac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctfac.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ZoomMin = 0;// 0.01 * m.GetExtents().Width; l.ZoomMax = /*0.9 * */ m.GetExtents().Width; l.OpacityMax = 0.5f; l.OpacityMin = 0.9f; l.HeatColorBlend = SharpMap.Layers.HeatLayer.Classic; var env = l.Envelope; GeoAPI.Geometries.GeoAPIEx.Grow(env, env.Width * 0.05, env.Height * 0.05); //m.EnforceMaximumExtents = true; //m.MaximumExtents = env; m.ZoomToBox(env); return(m); }
public void CanTransformPolygon() { ICoordinateTransformation transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory() .CreateFromCoordinateSystems( ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); IGeometry original = new Polygon(new LinearRing(new Coordinate[] { new Coordinate(-77.5, 38.5), new Coordinate(-77.1, 38.5), new Coordinate(-77.1, 38.1), new Coordinate(-77.5, 38.5) })); IGeometry transformed = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry( GeometryFactory.Default, original, transform.MathTransform); Assert.NotNull(transformed); Assert.IsTrue(transformed.IsValid); Assert.AreEqual(original, transformed); }
public static void ReprojectFeatureDataTable(SharpMap.Data.FeatureDataTable fdt, GeoAPI.CoordinateSystems.ICoordinateSystem target) { var source = SharpMap.CoordinateSystems.CoordinateSystemExtensions.GetCoordinateSystem(fdt[0].Geometry); var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctFactory.CreateFromCoordinateSystems(source, target); var geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory((int)target.AuthorityCode); for (var i = 0; i < fdt.Rows.Count; i++) { var fdr = fdt[i]; fdr.Geometry = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(fdr.Geometry, ct.MathTransform, geomFactory); } }
public void GeometryTransformTest() { #region Init ICoordinateTransformation // RGF93_Lambert_93 const string coordSysRGF93_Lambert_93 = "PROJCS[\"RGF93_Lambert_93\",GEOGCS[\"GCS_RGF_1993\",DATUM[\"D_RGF_1993\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",700000.0],PARAMETER[\"False_Northing\",6600000.0],PARAMETER[\"Central_Meridian\",3.0],PARAMETER[\"Standard_Parallel_1\",44.0],PARAMETER[\"Standard_Parallel_2\",49.0],PARAMETER[\"Latitude_Of_Origin\",46.5],UNIT[\"Meter\",1.0]]"; // SRID 4326 const string coordSys4326 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; var csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSysRGF93_Lambert_93) as GeoAPI.CoordinateSystems.ICoordinateSystem; var csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSys4326) as GeoAPI.CoordinateSystems.ICoordinateSystem; var transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); var piSource = ProjectionInfo.FromEsriString(coordSysRGF93_Lambert_93); var piTarget = ProjectionInfo.FromEsriString(coordSys4326); var dsTransform = new DotSpatialMathTransform(piSource, piTarget); #endregion Init ICoordinateTransformation using (var shapeDataReader = new ShapefileDataReader(@"..\..\..\NetTopologySuite.Samples.Shapefiles\DEPARTEMENT.SHP", GeometryFactory.Default)) { while (shapeDataReader.Read()) { var outGeomDotSpatial = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, dsTransform); Assert.IsFalse(outGeomDotSpatial.IsEmpty); Console.WriteLine(outGeomDotSpatial.AsText()); var outGeomProjNet = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, transform.MathTransform); Assert.IsFalse(outGeomProjNet.IsEmpty); Console.WriteLine(outGeomProjNet.AsText()); var hd = Algorithm.Distance.DiscreteHausdorffDistance.Distance(outGeomProjNet, outGeomDotSpatial); Console.WriteLine(string.Format("\nHaussdorffDistance: {0}", hd)); Console.WriteLine(); } } }
internal CoordinatesTransformer(ICoordinateSystem source, ICoordinateSystem target) { Debug.Assert(source != null); if (source == null) { throw new ArgumentNullException("source"); } Debug.Assert(target != null); if (target == null) { throw new ArgumentNullException("target"); } var factory = new ProjNetCS.Transformations.CoordinateTransformationFactory(); _Transformer = factory.CreateFromCoordinateSystems( CoordinateSystemUtils.Convert(source), CoordinateSystemUtils.Convert(target) ).MathTransform; }
public void TestEpsg3395AndEpsg4326() { var epsg3395 = @"PROJCS[""WGS 84 / World Mercator"",GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],AUTHORITY[""EPSG"",""6326""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.0174532925199433,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4326""]],PROJECTION[""Mercator_1SP""],PARAMETER[""Latitude_of_origin"", 0],PARAMETER[""central_meridian"",0],PARAMETER[""scale_factor"",1],PARAMETER[""false_easting"",0],PARAMETER[""false_northing"",0],UNIT[""metre"",1,AUTHORITY[""EPSG"",""9001""]],AXIS[""Easting"",EAST],AXIS[""Northing"",NORTH],AUTHORITY[""EPSG"",""3395""]]"; var epsg4326 = @"GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],AUTHORITY[""EPSG"",""6326""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.01745329251994328,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4326""]]"; var srcCRS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(epsg4326, Encoding.ASCII) as ICoordinateSystem; var tgtCRS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(epsg3395, Encoding.ASCII) as ICoordinateSystem; var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = ctFac.CreateFromCoordinateSystems(srcCRS, tgtCRS); var longitude = 102.709887; var latitude = 25.054263; var fromPT = new double[] { longitude, latitude }; var toPT = trans.MathTransform.Transform(fromPT); Assert.Equal(11433612.32, toPT[0], 2); Assert.Equal(2864322.39, toPT[1], 2); }
public void TestEpsg3857AndEpsg4326() { var epsg3857 = @"PROJCS[""WGS 84 / Pseudo - Mercator"", GEOGCS[""WGS 84"", DATUM[""WGS_1984"", SPHEROID[""WGS 84"", 6378137, 298.257223563, AUTHORITY[""EPSG"", ""7030""]], AUTHORITY[""EPSG"", ""6326""]], PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]], UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9122""]], AUTHORITY[""EPSG"", ""4326""]], PROJECTION[""Mercator_1SP""], PARAMETER[""Latitude_of_origin"", 0], PARAMETER[""central_meridian"", 0], PARAMETER[""scale_factor"", 1], PARAMETER[""false_easting"", 0], PARAMETER[""false_northing"", 0], UNIT[""metre"", 1, AUTHORITY[""EPSG"", ""9001""]], AXIS[""X"", EAST], AXIS[""Y"", NORTH], EXTENSION[""PROJ4"", "" + proj = merc + a = 6378137 + b = 6378137 + lat_ts = 0.0 + lon_0 = 0.0 + x_0 = 0.0 + y_0 = 0 + k = 1.0 + units = m + nadgrids = @null + wktext + no_defs""], AUTHORITY[""EPSG"", ""3857""]]"; var epsg4326 = @"GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],AUTHORITY[""EPSG"",""6326""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.01745329251994328,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4326""]]"; var srcCRS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(epsg4326, Encoding.ASCII) as ICoordinateSystem; var tgtCRS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(epsg3857, Encoding.ASCII) as ICoordinateSystem; var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = ctFac.CreateFromCoordinateSystems(srcCRS, tgtCRS); var longitude = 102.709887; var latitude = 25.054263; var fromPT = new double[] { longitude, latitude }; var toPT = trans.MathTransform.Transform(fromPT); Assert.Equal(11433612.32, toPT[0], 2); //TODO & FIXME: ProjNet did not works well with EPSG 4326 //Assert.Equal(2882411.08, toPT[1], 2); }
public static List<IPoint> projectGPSto23030(List<IPoint> wayPoints) { try { List<IPoint>projectedPoints=new List<IPoint>(); // p_WGS84=new Point(Lon,Lat); string ED50= "PROJCS[\"ED50 / UTM zone 30N\",GEOGCS[\"ED50\",DATUM[\"European_Datum_1950\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],AUTHORITY[\"EPSG\",\"6230\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4230\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-3],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],AUTHORITY[\"EPSG\",\"23030\"],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]"; // string WGS84 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; // string ETRS89="PROJCS[\"ETRS89 / UTM zone 30N\",GEOGCS[\"ETRS89\",DATUM[\"European_Terrestrial_Reference_System_1989\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6258\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4258\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-3],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],AUTHORITY[\"EPSG\",\"25830\"],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]"; var csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var cs1 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;//csf.CreateFromWkt(WGS84); var cs2 = csf.CreateFromWkt(ED50); var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctf.CreateFromCoordinateSystems(cs1, cs2).MathTransform; foreach(IPoint p in wayPoints) { double[] point=new double[2]; point[0]=p.X; point[1]=p.Y; double[] pointReturn = ct.Transform(point); IPoint projPoint= new Point(pointReturn[0],pointReturn[1]); projPoint.UserData=p.UserData; projectedPoints.Add(projPoint); } return projectedPoints; } catch (Exception ex) { throw ex; } }
private void Convert_To_State_Plane() { var x = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var projtarget = x.CreateFromWkt(Point.local_state_plane_wkt); try { var projsource = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var t = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = t.CreateFromCoordinateSystems(projsource, projtarget); double[] point = { (double)longitude, (double)latitude }; double[] convpoint = trans.MathTransform.Transform(point); state_plane_x = convpoint[0]; state_plane_y = convpoint[1]; } catch (Exception ex) { state_plane_x = 0; state_plane_y = 0; new ErrorLog(ex); } }
private void Convert_To_Lat_Long() { var x = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var projsource = x.CreateFromWkt(Point.local_state_plane_wkt); try { var projtarget = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var t = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = t.CreateFromCoordinateSystems(projsource, projtarget); double[] point = { state_plane_x, state_plane_y }; double[] convpoint = trans.MathTransform.Transform(point); latitude = (decimal)convpoint[1]; longitude = (decimal)convpoint[0]; } catch (Exception ex) { latitude = 0; longitude = 0; new ErrorLog(ex); } }
public LatLong(double?X, double?Y) { IsTested = true; if (!X.HasValue | !Y.HasValue) { // if we don't have a value for X or Y, we want to just quit here. return; } OriginalX = X.Value; OriginalY = Y.Value; IsValid = true; string source_wkt = @"PROJCS[""NAD_1983_HARN_StatePlane_Florida_East_FIPS_0901_Feet"",GEOGCS[""GCS_North_American_1983_HARN"",DATUM[""NAD83_High_Accuracy_Regional_Network"",SPHEROID[""GRS_1980"",6378137.0,298.257222101]],PRIMEM[""Greenwich"",0.0],UNIT[""Degree"",0.0174532925199433]],PROJECTION[""Transverse_Mercator""],PARAMETER[""False_Easting"",656166.6666666665],PARAMETER[""False_Northing"",0.0],PARAMETER[""Central_Meridian"",-81.0],PARAMETER[""Scale_Factor"",0.9999411764705882],PARAMETER[""Latitude_Of_Origin"",24.33333333333333],UNIT[""Foot_US"",0.3048006096012192]]"; var x = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var csource = x.CreateFromWkt(source_wkt); var ctarget = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var t = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = t.CreateFromCoordinateSystems(csource, ctarget); double[] point = { X.Value, Y.Value }; double[] convpoint = trans.MathTransform.Transform(point); Longitude = convpoint[0]; Latitude = convpoint[1]; }
private void ToLatLong() { //string source_wkt = @"PROJCS[""WGS 84 / Pseudo-Mercator"",GEOGCS[""Popular Visualisation CRS"",DATUM[""Popular_Visualisation_Datum"",SPHEROID[""Popular Visualisation Sphere"",6378137,0,AUTHORITY[""EPSG"",""7059""]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[""EPSG"",""6055""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.01745329251994328,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4055""]],UNIT[""metre"",1,AUTHORITY[""EPSG"",""9001""]],PROJECTION[""Mercator_1SP""],PARAMETER[""central_meridian"",0],PARAMETER[""scale_factor"",1],PARAMETER[""false_easting"",0],PARAMETER[""false_northing"",0],AUTHORITY[""EPSG"",""3785""],AXIS[""X"",EAST],AXIS[""Y"",NORTH]]"; var x = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var projsource = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator; //var csource = x.CreateFromWkt(source_wkt); var ctarget = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; var t = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var trans = t.CreateFromCoordinateSystems(projsource, ctarget); double[] point = { X, Y }; double[] convpoint = trans.MathTransform.Transform(point); OriginalLongitude = (decimal)convpoint[0]; OriginalLatitude = (decimal)convpoint[1]; Longitude = OriginalLongitude; Latitude = OriginalLatitude; //Longitude = Program.Truncate(OriginalLongitude, 5); //Latitude = Program.Truncate(OriginalLatitude, 5); //ShortLongitude = Program.Truncate(OriginalLongitude, 4); //ShortLatitude = Program.Truncate(OriginalLatitude, 4); }
public void TestTransformation() { var m = new SharpMap.Map(new System.Drawing.Size(640, 320)); var l = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("l", new SharpMap.Data.Providers.GeometryProvider(m.Factory.CreatePoint(new GeoAPI.Geometries.Coordinate(0, 51.478885))), SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(System.Drawing.Pens.Aquamarine, System.Drawing.Brushes.BurlyWood, 24)); var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); m.Layers.Add(new SharpMap.Layers.TileLayer(BruTile.Predefined.KnownTileSources.Create(), "b")); m.Layers.Add(l); var e = new GeoAPI.Geometries.Envelope(-0.02, 0.02, 51.478885 - 0.01, 51.478885 + 0.01); e = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformBox(e, l.CoordinateTransformation.MathTransform); m.ZoomToBox(e); m.GetMap().Save("Greenwich.png", System.Drawing.Imaging.ImageFormat.Png); }
public override void Reproject(ProjectionInfo targetProjection) { var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var csTarget = csFac.CreateFromWkt(targetProjection.ToEsriString()); foreach (var layer in EnumerateLayers(_map)) { var lLayer = layer as SharpMap.Layers.Layer; if (lLayer == null) { continue; } GeoAPI.CoordinateSystems.ICoordinateSystem csSource = null; if (lLayer.CoordinateTransformation != null) { csSource = lLayer.CoordinateTransformation.SourceCS; } if (!string.IsNullOrEmpty(layer.Proj4Projection)) { csSource = csFac.CreateFromWkt(ProjectionInfo.FromProj4String(layer.Proj4Projection).ToEsriString()); } else if (layer.SRID != 0) { csSource = csFac.CreateFromWkt(ProjectionInfo.FromEpsgCode(layer.SRID).ToEsriString()); } var ctF = ctFac.CreateFromCoordinateSystems(csSource, csTarget); var ctR = ctFac.CreateFromCoordinateSystems(csTarget, csSource); lLayer.CoordinateTransformation = ctF; lLayer.ReverseCoordinateTransformation = ctR; } throw new InvalidOperationException("Cannot Setup CoordinateTransformation as long as ProjectionInfo does not maintain SRID values."); }
public static Map Spherical() { //ICoordinateTransformation transformation = ProjHelper.LatLonToGoogle(); HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); IDictionary <string, LayerData> dict = Nyc; var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var pos = ctFac.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WebMercator); var neg = ctFac.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, GeographicCoordinateSystem.WGS84); foreach (string layer in dict.Keys) { string format = String.Format("~/App_Data/{0}", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } string name = Path.GetFileNameWithoutExtension(layer); LayerData data = dict[layer]; ShapeFile source = new ShapeFile(path, true); VectorLayer item = new VectorLayer(name, source) { //SRID = 4326, //TargetSRID = 900913, CoordinateTransformation = pos, ReverseCoordinateTransformation = neg, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias, IsQueryEnabled = true }; map.Layers.Add(item); } return(map); }
private static SharpMap.Map InitializeMapOsmWithXls(float angle) { var map = new SharpMap.Map(); var tileLayer = new SharpMap.Layers.TileAsyncLayer(new BruTile.Web.OsmTileSource(), "TileLayer - OSM with XLS"); map.BackgroundLayer.Add(tileLayer); //Get data from excel var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls"); var ds = new System.Data.DataSet("XLS"); using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath)) { cn.Open(); using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn))) da.Fill(ds); } #if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"); var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], 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], AUTHORITY[\"EPSG\",\"3857\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3857); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; coords = ct.MathTransform.Transform(coords); row["X"] = coords[0]; row["Y"] = coords[1]; } #else var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var epsg3857 = DotSpatial.Projections.ProjectionInfo.FromEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], 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], AUTHORITY[\"EPSG\",\"3857\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3857, 0, 1); row["X"] = coords[0]; row["Y"] = coords[1]; } #endif //Add Rotation Column ds.Tables[0].Columns.Add("Rotation", typeof (float)); foreach (System.Data.DataRow row in ds.Tables[0].Rows) row["Rotation"] = -angle; //Set up provider var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y"); var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider) {Style = {Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol}}; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel") { DataSource = xlsProvider, LabelColumn = "Name", PriorityColumn = "Population", Style = { CollisionBuffer = new System.Drawing.SizeF(2f, 2f), CollisionDetection = true }, LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection }; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
private static GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation GetCoordinateTransformation() { //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"); var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], 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], AUTHORITY[\"EPSG\",\"3857\"]]"); return ctf.CreateFromCoordinateSystems(epsg4326, epsg3857);
public static void ReprojectFeatureDataTable(SharpMap.Data.FeatureDataTable fdt, GeoAPI.CoordinateSystems.ICoordinateSystem target) { var source = SharpMap.CoordinateSystems.CoordinateSystemExtensions.GetCoordinateSystem(fdt[0].Geometry); var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var ct = ctFactory.CreateFromCoordinateSystems(source, target); var geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory((int)target.AuthorityCode); for (var i = 0; i < fdt.Rows.Count; i++) { var fdr = fdt[i]; fdr.Geometry = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(fdr.Geometry, ct.MathTransform, geomFactory); } }
public void CanTransformPolygon() { ICoordinateTransformation transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory() .CreateFromCoordinateSystems( ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); IGeometry original = new Polygon(new LinearRing(new Coordinate[]{ new Coordinate(-77.5, 38.5),new Coordinate(-77.1, 38.5),new Coordinate(-77.1, 38.1),new Coordinate(-77.5, 38.5)})); IGeometry transformed = NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry( GeometryFactory.Default, original, transform.MathTransform); Assert.NotNull(transformed); Assert.IsTrue(transformed.IsValid); Assert.AreEqual(original, transformed); }
public void TestTransformation() { var m = new SharpMap.Map(new System.Drawing.Size(640, 320)); var l = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("l", new SharpMap.Data.Providers.GeometryProvider(m.Factory.CreatePoint(new GeoAPI.Geometries.Coordinate(0, 51.478885))), SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(System.Drawing.Pens.Aquamarine, System.Drawing.Brushes.BurlyWood, 24)); var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); m.Layers.Add(new SharpMap.Layers.TileLayer(new BruTile.Web.OsmTileSource(),"b")); m.Layers.Add(l); var e = new GeoAPI.Geometries.Envelope(-0.02, 0.02, 51.478885 - 0.01, 51.478885 + 0.01); e = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformBox(e, l.CoordinateTransformation.MathTransform); m.ZoomToBox(e); m.GetMap().Save("Greenwich.png", System.Drawing.Imaging.ImageFormat.Png); }
public override void Reproject(ProjectionInfo targetProjection) { var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var csTarget = csFac.CreateFromWkt(targetProjection.ToEsriString()); foreach (var layer in EnumerateLayers(_map)) { var lLayer = layer as SharpMap.Layers.Layer; if (lLayer == null) continue; GeoAPI.CoordinateSystems.ICoordinateSystem csSource = null; if (lLayer.CoordinateTransformation != null) { csSource = lLayer.CoordinateTransformation.SourceCS; } if (!string.IsNullOrEmpty(layer.Proj4Projection)) { csSource = csFac.CreateFromWkt(ProjectionInfo.FromProj4String(layer.Proj4Projection).ToEsriString()); } else if (layer.SRID != 0) { csSource = csFac.CreateFromWkt(ProjectionInfo.FromEpsgCode(layer.SRID).ToEsriString()); } var ctF = ctFac.CreateFromCoordinateSystems(csSource, csTarget); var ctR = ctFac.CreateFromCoordinateSystems(csTarget, csSource); lLayer.CoordinateTransformation = ctF; lLayer.ReverseCoordinateTransformation = ctR; } throw new InvalidOperationException("Cannot Setup CoordinateTransformation as long as ProjectionInfo does not maintain SRID values."); }
public void GeometryTransformTest() { #region Init ICoordinateTransformation // RGF93_Lambert_93 const string coordSysRGF93_Lambert_93 = "PROJCS[\"RGF93_Lambert_93\",GEOGCS[\"GCS_RGF_1993\",DATUM[\"D_RGF_1993\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",700000.0],PARAMETER[\"False_Northing\",6600000.0],PARAMETER[\"Central_Meridian\",3.0],PARAMETER[\"Standard_Parallel_1\",44.0],PARAMETER[\"Standard_Parallel_2\",49.0],PARAMETER[\"Latitude_Of_Origin\",46.5],UNIT[\"Meter\",1.0]]"; // SRID 4326 const string coordSys4326 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; var csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSysRGF93_Lambert_93) as GeoAPI.CoordinateSystems.ICoordinateSystem; var csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSys4326) as GeoAPI.CoordinateSystems.ICoordinateSystem; var transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); var piSource = ProjectionInfo.FromEsriString(coordSysRGF93_Lambert_93); var piTarget = ProjectionInfo.FromEsriString(coordSys4326); var dsTransform = new DotSpatialMathTransform(piSource, piTarget); #endregion Init ICoordinateTransformation using (var shapeDataReader = new ShapefileDataReader(@"..\..\..\NetTopologySuite.Samples.Shapefiles\DEPARTEMENT.SHP", GeometryFactory.Default)) { while (shapeDataReader.Read()) { var outGeomDotSpatial = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, dsTransform); Assert.IsFalse(outGeomDotSpatial.IsEmpty); Console.WriteLine(outGeomDotSpatial.AsText()); var outGeomProjNet = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, transform.MathTransform); Assert.IsFalse(outGeomProjNet.IsEmpty); Console.WriteLine(outGeomProjNet.AsText()); var hd = Algorithm.Distance.DiscreteHausdorffDistance.Distance(outGeomProjNet, outGeomDotSpatial); Console.WriteLine(string.Format("\nHaussdorffDistance: {0}", hd)); Console.WriteLine(); } } }