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 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); }
/// <summary> /// Static constructor to perform 1-time initialisation. /// </summary> static MapView() { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices(); var coordFactory = new ProjNet.CoordinateSystems.CoordinateSystemFactory(System.Text.Encoding.Unicode); var css = new SharpMap.CoordinateSystems.CoordinateSystemServices(coordFactory, new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()); css.AddCoordinateSystem(3857, coordFactory.CreateFromWkt("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\"]], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], PROJECTION[\"Mercator_1SP\"], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 0], PARAMETER[\"scale_factor\", 1], PARAMETER[\"false_easting\", 0], PARAMETER[\"false_northing\", 0], AUTHORITY[\"EPSG\", \"3857\"]]")); css.AddCoordinateSystem(4326, coordFactory.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.0174532925199433, AUTHORITY[\"EPSG\", \"9122\"]], AUTHORITY[\"EPSG\", \"4326\"]]")); SharpMap.Session.Instance .SetGeometryServices(GeoAPI.GeometryServiceProvider.Instance) .SetCoordinateSystemServices(css) .SetCoordinateSystemRepository(css); }
private void Print(Dictionary <int, Catchment> AllCatchments, string FileNameAttach) { //Get the output coordinate system ProjNet.CoordinateSystems.ICoordinateSystem projection; using (System.IO.StreamReader sr = new System.IO.StreamReader(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Default.prj"))) { ProjNet.CoordinateSystems.CoordinateSystemFactory cs = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); projection = cs.CreateFromWkt(sr.ReadToEnd()); } using (ShapeWriter sw = new ShapeWriter(Path.Combine(Path.GetDirectoryName(OutputFile.FileName), Path.GetFileNameWithoutExtension(OutputFile.FileName) + FileNameAttach)) { Projection = projection }) { for (int i = 0; i < ReductionVariables.Rows.Count; i++) { GeoRefData gd = new GeoRefData() { Data = ReductionVariables.Rows[i], Geometry = AllCatchments[(int)ReductionVariables.Rows[i]["ID"]].Geometry }; sw.Write(gd); } } }
/// <summary> /// Creates a new point shape file. Overwrite if it exists. /// </summary> /// <param name="FileName"></param> public ShapeWriter(string FileName):base() { _fileName = FileName; ProjNet.CoordinateSystems.CoordinateSystemFactory cs = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); projection = cs.CreateFromWkt(@"PROJCS["")ETRS_1989_UTM_Zone_32N"",GEOGCS[""GCS_ETRS_1989"",DATUM[""D_ETRS_1989"",SPHEROID[""GRS_1980"",6378137.0,298.257222101]],PRIMEM[""Greenwich"",0.0],UNIT[""Degree"",0.0174532925199433]],PROJECTION[""Transverse_Mercator""],PARAMETER[""False_Easting"",500000.0],PARAMETER[""False_Northing"",0.0],PARAMETER[""Central_Meridian"",9.0],PARAMETER[""Scale_Factor"",0.9996],PARAMETER[""Latitude_Of_Origin"",0.0],UNIT[""Meter"",1.0]]"); _dbf = new DBFWriter(FileName); }
private const string XY_M = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; //NOXLATE internal ActualCoordinateSystem(ProjNet.CoordinateSystems.CoordinateSystem coordinateSystem) { if (coordinateSystem == null) { throw new ArgumentNullException(nameof(coordinateSystem)); //NOXLATE } var f = new CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M)); }
public static ProjNet.CoordinateSystems.ICoordinateSystem Convert(ICoordinateSystem system) { if (system==null) return null; var ret=system as ProjNet.CoordinateSystems.ICoordinateSystem; if (ret==null) { var factory=new ProjNet.CoordinateSystems.CoordinateSystemFactory(); ret=factory.CreateFromWkt(system.ToString()); } return ret; }
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 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 ProjNet.CoordinateSystems.ICoordinateSystem Convert(ICoordinateSystem system) { if (system == null) { return(null); } var ret = system as ProjNet.CoordinateSystems.ICoordinateSystem; if (ret == null) { var factory = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); ret = factory.CreateFromWkt(system.ToString()); } return(ret); }
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); } }
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 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 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; } }
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."); }
private static Map InitializeMapOsmWithXls(float angle) { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS"); map.Layers.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 epsg3785 = 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\",\"3785\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { 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 epsg3785 = new DotSpatial.Projections.ProjectionInfo(); epsg3785.ReadEsriString("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\",\"3785\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 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); xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel"); xlsLabelLayer.DataSource = xlsProvider; xlsLabelLayer.LabelColumn = "Name"; xlsLabelLayer.PriorityColumn = "Population"; xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f); xlsLabelLayer.Style.CollisionDetection = true; xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
private static 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 epsg3785 = 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\",\"3785\"]]"); return ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
private void Print(Dictionary<int, Catchment> AllCatchments, string FileNameAttach) { //Get the output coordinate system ProjNet.CoordinateSystems.ICoordinateSystem projection; using (System.IO.StreamReader sr = new System.IO.StreamReader(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Default.prj"))) { ProjNet.CoordinateSystems.CoordinateSystemFactory cs = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); projection = cs.CreateFromWkt(sr.ReadToEnd()); } using (ShapeWriter sw = new ShapeWriter(Path.Combine(Path.GetDirectoryName(OutputFile.FileName),Path.GetFileNameWithoutExtension(OutputFile.FileName)+FileNameAttach)) { Projection = projection }) { for (int i = 0; i < ReductionVariables.Rows.Count; i++) { GeoRefData gd = new GeoRefData() { Data = ReductionVariables.Rows[i], Geometry = AllCatchments[(int)ReductionVariables.Rows[i]["ID"]].Geometry }; sw.Write(gd); } } }
public void DebugPrint() { string dir = Path.GetDirectoryName(AlldataFile.FileName); foreach (var s in InternalReductionModels) s.DebugPrint(dir, AllCatchments); foreach (var s in MainStreamRecutionModels) s.DebugPrint(dir, AllCatchments); foreach (var s in SourceModels) s.DebugPrint(dir, AllCatchments); //Get the output coordinate system ProjNet.CoordinateSystems.ICoordinateSystem projection; using (System.IO.StreamReader sr = new System.IO.StreamReader(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Default.prj"))) { ProjNet.CoordinateSystems.CoordinateSystemFactory cs = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); projection = cs.CreateFromWkt(sr.ReadToEnd()); } }
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); }