ThinkGeo.com    |     Documentation    |     Premium Support

How do I get the current projection of a shapefile?

For files received several shapes and need to know which file is this projection.



Hello Carlos Angelo, 
  
 There will be *.prj file with the shapefile together, it will tell you what’ the projection for each shape file. 
  
 Regards, 
  
 Gary

Hello,

is it possible to directly get a ManagedProj4Projection (which takes a proj4 parameter string as input) out of the OGR projection specified in a shapefile?
That would make it possible to load arbitrary shapefiles without requiring the user to specify the projection manually.

Regards,
Markus

Hi Markus,

If a .shp contains a same name .prj file, you can write code to read that just like read a text file and then assign that to ManagedProj4Projection.

If the .prj file don’t exist, your user had to specified it.

The .shp file don’t contains projection information in itself.

Regards,

Don

Hi Don,

that would be great if the projection could be set this way, though I get this error:

System.Exception: Parameters is null��
   bei xRM=.ZDQ=.cTQ=(String args)
   bei ThinkGeo.MapSuite.Core.ManagedProj4Projection.OpenCore()
   bei ThinkGeo.MapSuite.Core.Projection.Open()

when executing

     var projection = new ManagedProj4Projection
                {
                    InternalProjectionParametersString = 
@"GEOGCS[""GCS_WGS_1984"",DATUM[""D_WGS_1984"",SPHEROID[""WGS_1984"",6378137,298.257223563]],PRIMEM[""Greenwich"",0],UNIT[""Degree"",0.017453292519943295]]",
                    ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(3857)
                };
                projection.Open();

The projection parameters are taken from the .prj file.

Regards,
Markus

Hi Markus,

Please try this code:

InternalProjectionParametersString = ManagedProj4Projection.ConvertPrjToProj4(@“GEOGCS[”“GCS_WGS_1984"”,DATUM["“D_WGS_1984"”,SPHEROID["“WGS_1984"”,6378137,298.257223563]],PRIMEM["“Greenwich”",0],UNIT["“Degree”",0.017453292519943295]]")

Regards,

Don

Thank you for the code, it works.
Wouldn’t it be good idea to document this feature or how am I supposed to discover this if not asking in the forum?
We did lots of effort to let the user specify the correct projection.

Regards,
Markus

Hi Markus,

Our documentation is not enough now, we will make it more detail in future.

If you have any question, you can tried to search on forum and wiki, then submit topic here.

Wish that’s helpful.

Regards,

Don