private static ProjectionCategory GetProjectionCategory(ProjectionInfo projectionInfo) { var holder = projectionInfo.IsLatLon ? (ICoordinateSystemCategoryHolder)KnownCoordinateSystems.Geographic : KnownCoordinateSystems.Projected; var selectedAsStr = projectionInfo.ToString(); var selectedEsri = projectionInfo.ToEsriString(); foreach (var name in holder.Names) { var cat = holder.GetCategory(name); foreach (var projName in cat.Names) { var proj = cat.GetProjection(projName); if (proj.ToString() == selectedAsStr && proj.ToEsriString() == selectedEsri) { return(new ProjectionCategory { CategoryName = name, ProjectionFieldName = projName }); } } } return(null); }
public void ToEsriStringWGS1984Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.World.WGS1984; const string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
public void ToEsriStringNorthAmericanDatum1983Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.NorthAmerica.NorthAmericanDatum1983; const string esri = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101004]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
private void ForceMaxExtentZoom() { ProjectionInfo webMerc = KnownCoordinateSystems.Projected.World.WebMercator; //special case when there are no other layers in the map. Set map projection to WebMercator and zoom to max ext. MapFrameProjectionHelper.ReprojectMapFrame(App.Map.MapFrame, webMerc.ToEsriString()); // modifying the view extents didn't get the job done, so we are creating a new featureset. // App.Map.ViewExtents = new Extent(TileCalculator.MinWebMercX, TileCalculator.MinWebMercY, TileCalculator.MaxWebMercX, TileCalculator.MaxWebMercY); var fs = new FeatureSet(FeatureType.Point); fs.Features.Add(new Coordinate(TileCalculator.MinWebMercX, TileCalculator.MinWebMercY)); fs.Features.Add(new Coordinate(TileCalculator.MaxWebMercX, TileCalculator.MaxWebMercY)); fs.Projection = App.Map.Projection; _featureSetLayer = App.Map.Layers.Add(fs); // hide the points that we are adding. _featureSetLayer.LegendItemVisible = false; App.Map.ZoomToMaxExtent(); }
private static ProjectionCategory GetProjectionCategory(ProjectionInfo projectionInfo) { var holder = projectionInfo.IsLatLon ? (ICoordinateSystemCategoryHolder)KnownCoordinateSystems.Geographic : KnownCoordinateSystems.Projected; var selectedAsStr = projectionInfo.ToString(); var selectedEsri = projectionInfo.ToEsriString(); foreach (var name in holder.Names) { var cat = holder.GetCategory(name); foreach (var projName in cat.Names) { var proj = cat.GetProjection(projName); if (proj.ToString() == selectedAsStr && proj.ToEsriString() == selectedEsri) { return new ProjectionCategory { CategoryName = name, ProjectionFieldName = projName }; } } } return null; }
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 void UpdateProjectionStrings() { txtEsriString.Text = _projection.ToEsriString(); txtProj4String.Text = _projection.ToProj4String(); }
private void EnableBasemapFetching(string tileServerName, string tileServerUrl) { ProjectionInfo webMerc = KnownCoordinateSystems.Projected.World.WebMercator; // Zoom out as much as possible if there are no other layers. //reproject any existing layer in non-webMercator projection. //if (App.Map.Layers.Count == 0 || App.Map.Projection != webMerc) if (App.Map.Layers.Count == 0) { ForceMaxExtentZoom(); } else if (!App.Map.Projection.Equals(webMerc)) { //get original view extents App.ProgressHandler.Progress(String.Empty, 0, "Reprojecting Map Layers..."); double[] viewExtentXY = new[] { App.Map.ViewExtents.MinX, App.Map.ViewExtents.MinY, App.Map.ViewExtents.MaxX, App.Map.ViewExtents.MaxY }; double[] viewExtentZ = new[] { 0.0, 0.0 }; //reproject view extents Reproject.ReprojectPoints(viewExtentXY, viewExtentZ, App.Map.Projection, webMerc, 0, 2); //set the new map extents App.Map.ViewExtents = new Extent(viewExtentXY); //if projection is not WebMercator - reproject all layers: MapFrameProjectionHelper.ReprojectMapFrame(App.Map.MapFrame, webMerc.ToEsriString()); App.ProgressHandler.Progress(String.Empty, 0, "Loading Basemap..."); } // Special case for WMS if (tileServerName.Equals(Properties.Resources.WMSMap, StringComparison.InvariantCultureIgnoreCase)) { using (var wmsDialog = new WMSServerParameters()) { if (wmsDialog.ShowDialog() != DialogResult.OK) { return; } _tileManager.WmsServerInfo = wmsDialog.WmsServerInfo; } } // Other is a custom service if (tileServerName.Equals(Other, StringComparison.InvariantCultureIgnoreCase)) { tileServerUrl = Interaction.InputBox("Please provide the Url for the service.", DefaultResponse: "http://tiles.virtualearth.net/tiles/h{key}.jpeg?g=461&mkt=en-us&n=z"); // Let the user cancel... if (String.IsNullOrWhiteSpace(tileServerUrl)) { return; } } EnableBasemapLayer(); _tileManager.ChangeService(tileServerName, tileServerUrl); if (_bw.IsBusy != true) { _bw.RunWorkerAsync(); } }