Skip to content

Create CoordinateSystem by Well known text

FObermaier edited this page Jul 10, 2018 · 1 revision
string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
GeoAPI.CoordinateSystems.ICoordinateSystem cs =    
    ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as GeoAPI.CoordinateSystems.ICoordinateSystem;

If you know that the WKT is for instance a geographic coordinate system as above, you can instead cast it to that if necessary:

GeoAPI.CoordinateSystems.IGeographicCoordinateSystem gcs =   
    ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt_geo) as GeoAPI.CoordinateSystems.IGeographicCoordinateSystem;

and similar for a projected coordinate system:

GeoAPI.CoordinateSystems.IProjectedCoordinateSystem pcs =   
    ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt_proj) as GeoAPI.CoordinateSystems.IProjectedCoordinateSystem;