Reputation: 55
I'm reading the shp file using NetTopologySuite.IO.ShapefileDataReader, but believe I also need to process the prj file. Is there an api to read the prj file? (The prj file is mentioned here: https://en.wikipedia.org/wiki/Shapefile)
I've tried looking through the NetTopologySuite.IO namespace to find a reader for prj files, but haven't identified one, I also tried looking at the result from NetTopologySuite.IO.ShapefileDataReader.Read(), but didn't see the data stored in the prj file.
Upvotes: 3
Views: 1683
Reputation: 582
There are several libraries for reading .prj files:
https://www.nuget.org/packages/ProjNet/
https://www.nuget.org/packages/DotSpatial.Projections/
https://www.nuget.org/packages/GDAL/
https://www.nuget.org/packages/SharpProj.NetTopologySuite/
You really only need to process the .prj file if you are reprojecting coordinates to another coordinate system; such as for displaying data from different coordinate systems on top of one another in a single map or for doing linear measurements in a projected coordinate system. I will provide a few examples how to read the .prj file, below. All of the projects linked have methods for loading, reprojecting, and saving prj files.
In ProjNet, you can read the projection file with the CoordinateSystemWktReader:
public void ReadProjection(string filename)
{
var projection = CoordinateSystemWktReader.Parse(File.ReadAllText(filename)) as CoordinateSystem;
}
In GDAL, SpatialReference
class holds methods for managing the projection information:
public void ReadProjection(string filename)
{
// Read in the vector data
Driver driver = Ogr.GetDriverByName("ESRI Shapefile");
DataSource inDataSource = driver.Open(filename, 0);
OSGeo.OGR.Layer inLayer = inDataSource.GetLayerByIndex(0);
SpatialReference srcSrs = inLayer.GetSpatialRef();
inDataSource.FlushCache()
inDataSource.Dispose()
}
In DotSpatial.Projections:
public void ReadProjection(string filename)
{
var projection = ProjectionInfo.Open(filename);
}
Upvotes: 4