public static void Run() { //ExStart: ExportSpatialReferenceSystemToWKT var parameters = new ProjectedSpatialReferenceSystemParameters { Name = "WGS 84 / World Mercator", Base = SpatialReferenceSystem.Wgs84, ProjectionMethodName = "Mercator_1SP", LinearUnit = Unit.Meter, XAxis = new Axis("Easting", AxisDirection.East), YAxis = new Axis("Northing", AxisDirection.North), AxisesOrder = ProjectedAxisesOrder.XY, }; parameters.AddProjectionParameter("central_meridian", 0); parameters.AddProjectionParameter("scale_factor", 1); parameters.AddProjectionParameter("false_easting", 0); parameters.AddProjectionParameter("false_northing", 0); var projectedSrs = SpatialReferenceSystem.CreateProjected(parameters, Identifier.Epsg(3395)); string wkt = projectedSrs.ExportToWkt(); Console.WriteLine(wkt); //ExEnd: ExportSpatialReferenceSystemToWKT }
private void Client_GetAllSitesCompleted(object sender, GetAllSitesCompletedEventArgs e) { if (e.Error != null) { CurrentAction = UserAction.Idle; GeneralInfo.Content = "Failed to search sites"; return; } if (e.Result != null) { foreach (GraphicsLayer layer in _GraphicsLayers.Values) { layer.Graphics.Clear(); } foreach (var s in e.Result) { Graphic graphic = new Graphic(); double[] lonlat = SpatialReferenceSystem.ToWebMercator(s.Longitude, s.Latitude); graphic.Geometry = new MapPoint(lonlat[0], lonlat[1]); graphic.Symbol = _MarkerSymbols[s.SiteType];; graphic.Attributes.Add("Name", s.Name); graphic.Attributes.Add("Site", s); _GraphicsLayers[s.SiteType].Graphics.Add(graphic); } CurrentAction = UserAction.Idle; GeneralInfo.Content = e.Result.Count + " sites found"; } else { CurrentAction = UserAction.Idle; GeneralInfo.Content = "No sites found"; } }
public void Creat(GraphicsLayer layer, RegularGrid grid) { _GraphicsLayer = layer; var cellsize = grid.CellSize * 0.5; var polygon = new Polygon(); for (int i = 0; i < grid.NCell; i++) { var symbol = GetDefaultSymbol(polygon, System.Windows.Media.Colors.White); ESRI.ArcGIS.Client.Geometry.PointCollection pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); var buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] + cellsize); MapPoint p1 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] + cellsize, grid.CentroidY[i] + cellsize); MapPoint p2 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] + cellsize, grid.CentroidY[i] - cellsize); MapPoint p3 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] - cellsize); MapPoint p4 = new MapPoint(buf[0], buf[1]); buf = SpatialReferenceSystem.ToWebMercator(grid.CentroidX[i] - cellsize, grid.CentroidY[i] + cellsize); MapPoint p5 = new MapPoint(buf[0], buf[1]); pc.Add(p1); pc.Add(p2); pc.Add(p3); pc.Add(p4); pc.Add(p5); Graphic graphic = new Graphic(); Polygon ep = new Polygon(); ep.Rings.Add(pc); graphic.Geometry = ep; graphic.Symbol = symbol; graphic.Attributes.Add("ID", i); layer.Graphics.Add(graphic); } }
public static void Run() { //ExStart: CreateFromEpsgCode var srs = SpatialReferenceSystem.CreateFromEpsg(26918); Console.WriteLine("SRS Name: {0}", srs.Name); // NAD83 / UTM zone 18N Console.WriteLine("SRS EPSG code: {0}", srs.EpsgCode); // 26918 Console.WriteLine("Datum name: {0}", srs.GeographicDatum.Name); // North_American_Datum_1983 Console.WriteLine("Datum EPSG code: {0}", srs.GeographicDatum.EpsgCode); // 6269 Console.WriteLine("Ellipsoid name: {0}", srs.GeographicDatum.Ellipsoid.Name); // GRS 1980 Console.WriteLine("Ellipsoid EPSG code: {0}", srs.GeographicDatum.EpsgCode); // 6269 Console.WriteLine("Type: {0}", srs.Type); // Projected Console.WriteLine("Dimensions count: {0}", srs.DimensionsCount); // 2 Console.WriteLine("First dimension name: {0}", srs.GetAxis(0).Name); // X Console.WriteLine("First dimension direction: {0}", srs.GetAxis(0).Direction); // East Console.WriteLine("Second dimension name: {0}", srs.GetAxis(1).Name); // Y Console.WriteLine("Second dimension direction: {0}", srs.GetAxis(1).Direction); // North Console.WriteLine("First dimension unit: {0}, {1}", srs.GetUnit(0).Name, srs.GetUnit(0).Factor); // metre, 1 Console.WriteLine("Second dimension unit: {0}, {1}", srs.GetUnit(1).Name, srs.GetUnit(1).Factor); // metre, 1 //ExEnd: CreateFromEpsgCode }
public T ToGeometry <T>() where T : Geometry { GeoJSONParser <T> geoJSONParser = (Object)srsId != null ? new GeoJSONParser <T>(SpatialReferenceSystem.GetName(srsId), geomClass) : new GeoJSONParser <T>(geomClass); T result = (T)geoJSONParser.Read(this.geoJSON); return(result); }
public static void RenderToSpecificProjection() { //ExStart: RenderToSpecificProjection using (var map = new Map(800, 400)) { map.Add(VectorLayer.Open(dataDir + "land.shp", Drivers.Shapefile)); map.SpatialReferenceSystem = SpatialReferenceSystem.CreateFromEpsg(54024); // World Bonne map.Render(dataDir + "land_out.svg", Renderers.Svg); } //ExEnd: RenderToSpecificProjection }
public static void Run() { string dataDir = RunExamples.GetDataDir(); //ExStart: CreateVectorLayerWithSpatialReferenceSystem var parameters = new ProjectedSpatialReferenceSystemParameters { Name = "WGS 84 / World Mercator", Base = SpatialReferenceSystem.Wgs84, ProjectionMethodName = "Mercator_1SP", LinearUnit = Unit.Meter, XAxis = new Axis("Easting", AxisDirection.East), YAxis = new Axis("Northing", AxisDirection.North), AxisesOrder = ProjectedAxisesOrder.XY, }; parameters.AddProjectionParameter("central_meridian", 0); parameters.AddProjectionParameter("scale_factor", 1); parameters.AddProjectionParameter("false_easting", 0); parameters.AddProjectionParameter("false_northing", 0); var projectedSrs = SpatialReferenceSystem.CreateProjected(parameters, Identifier.Epsg(3395)); using (var layer = Drivers.Shapefile.CreateLayer(dataDir + "filepath_out.shp", new ShapefileOptions(), projectedSrs)) { var feature = layer.ConstructFeature(); feature.Geometry = new Point(1, 2); layer.Add(feature); feature = layer.ConstructFeature(); feature.Geometry = new Point(1, 2) { SpatialReferenceSystem = SpatialReferenceSystem.Nad83 }; try { layer.Add(feature); // geometry of feature has different SRS - exception is thrown } catch (GisException e) { Console.WriteLine(e.Message); } } using (var layer = Drivers.Shapefile.OpenLayer(dataDir + "filepath_out.shp")) { var srsName = layer.SpatialReferenceSystem.Name; // "WGS 84 / World Mercator" layer.SpatialReferenceSystem.IsEquivalent(projectedSrs); // true } //ExEnd: CreateVectorLayerWithSpatialReferenceSystem }
private void Map_MouseMove(object sender, MouseEventArgs e) { System.Windows.Point screenPoint = e.GetPosition(Map); ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = Map.ScreenToMap(screenPoint); if (Map.WrapAroundIsActive) { mapPoint = ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mapPoint) as ESRI.ArcGIS.Client.Geometry.MapPoint; } if (mapPoint != null) { var pt = SpatialReferenceSystem.ToGeographic(mapPoint.X, mapPoint.Y); if (pt != null) { lonLabel.Content = pt[0].ToString("0.0000"); latLabel.Content = pt[1].ToString("0.0000"); } } }
public static void Run() { //ExStart: CreateFromWkt string wkt = @" 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 srs = SpatialReferenceSystem.CreateFromWkt(wkt); Console.WriteLine("SRS Name: {0}", srs.Name); // WGS 84 Console.WriteLine("SRS EPSG code: {0}", srs.EpsgCode); // 4326 Console.WriteLine("Datum name: {0}", srs.GeographicDatum.Name); // WGS_1984 Console.WriteLine("Datum EPSG code: {0}", srs.GeographicDatum.EpsgCode); // 6326 Console.WriteLine("Ellipsoid name: {0}", srs.GeographicDatum.Ellipsoid.Name); // WGS 84 Console.WriteLine("Ellipsoid EPSG code: {0}", srs.GeographicDatum.EpsgCode); // 7030 Console.WriteLine("Type: {0}", srs.Type); // Geographic Console.WriteLine("Dimensions count: {0}", srs.DimensionsCount); // 2 Console.WriteLine("First dimension name: {0}", srs.GetAxis(0).Name); // Longitude Console.WriteLine("First dimension direction: {0}", srs.GetAxis(0).Direction); // EAST Console.WriteLine("Second dimension name: {0}", srs.GetAxis(1).Name); // Latitude Console.WriteLine("Second dimension direction: {0}", srs.GetAxis(1).Direction); // NORTH Console.WriteLine("First dimension unit: {0}, {1}", srs.GetUnit(0).Name, srs.GetUnit(0).Factor); // degree, 0.01745... Console.WriteLine("Second dimension unit: {0}, {1}", srs.GetUnit(1).Name, srs.GetUnit(1).Factor); // degree, 0.01745... var geogSrs = srs.AsGeographic; Console.WriteLine("Angular unit: {0}, {1}", geogSrs.AngularUnit.Name, geogSrs.AngularUnit.Factor); // degree, 0.01745... Console.WriteLine("Prime meridian: {0}, {1}", geogSrs.PrimeMeridian.Name, geogSrs.PrimeMeridian.Longitude); // Greenwich, 0 //ExEnd: CreateFromWkt }
public static void Run() { //ExStart: CompareSpatialReferenceSystems string wkt = @" 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 srs = SpatialReferenceSystem.CreateFromWkt(wkt); srs.IsEquivalent(SpatialReferenceSystem.Wgs84); // true //ExEnd: CompareSpatialReferenceSystems }
public static void Run() { string dataDir = RunExamples.GetDataDir(); string path = dataDir + "SpecifyLayerSpatialReference_out.shp"; //ExStart: SpecifyLayerSpatialReference var srs = SpatialReferenceSystem.CreateFromEpsg(26918); using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile, srs)) { var feature = layer.ConstructFeature(); feature.Geometry = new Point(60, 24); layer.Add(feature); } using (VectorLayer layer = VectorLayer.Open(path, Drivers.Shapefile)) { Console.WriteLine(layer.SpatialReferenceSystem.EpsgCode); // 26918 Console.WriteLine(layer.SpatialReferenceSystem.Name); // NAD83_UTM_zone_18N } //ExEnd: SpecifyLayerSpatialReference }
void IConfig.SetReferenceSystem(SpatialReferenceSystem id) { SetReferenceSystem(id); }
private static void SetReferenceSystem(SpatialReferenceSystem spatialReference) { _spatialReferenceSystemId = (int)spatialReference; }