Spatial Reference Systems
Contents
[
Hide
]
Creating Spatial Reference Systems
Create a Spatial Reference System by a EPSG Identifier (SRID)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
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 |
Create a Spatial Reference System from WKT (Well-Known text)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
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 |
Create Spatial Reference System with Custom Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
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", 100); | |
parameters.AddProjectionParameter("false_northing", 100); | |
var projectedSrs = SpatialReferenceSystem.CreateProjected(parameters, Identifier.Epsg(3395)); |
Working with Spatial Reference Systems
Check Driver Support for a Spatial Reference System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
Drivers.Shapefile.SupportsSpatialReferenceSystem(SpatialReferenceSystem.Wgs72); // true | |
Drivers.GeoJson.SupportsSpatialReferenceSystem(SpatialReferenceSystem.Wgs84); // true | |
Drivers.GeoJson.SupportsSpatialReferenceSystem(SpatialReferenceSystem.Wgs72); // false |
Export Spatial Reference System to WKT
Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. Aspose.GIS API lets you create a Spatial Reference System from WKT as shown in the following sample code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
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); |
Compare Spatial Reference Systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
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 |