For you, what is the difference between geographic coordinates and projected coordinates ?
From ESRI GeoNet: Projected Coordinate System vs. Geographic Coordinate System:
- A Geographic Coordinate Systems is defined by a 3-D surface and is measured in latitude and longitude.
- A Projected Coordinate systems refers to data that is defined by a flat 2-D surface and can be measured in units of meters and feet.
- When displaying data that's using a geographic coordinate system, ArcMap uses a 'pseudo-Plate Carree' projection. Basically, it just treat the coordinate values as if they're linear and just display the data.
Therefore if your coordinates are lat & lon variables, you use a Geographic Coordinate System (sensu ESRI)
1) With osgeo.ogr and a shapefile with WGS84 projection (Geographic Coordinate System), the crs is found by:
from osgeo import ogr
infile = ogr.Open("aWGS84.shp")
layer = infile.GetLayer()
# crs
spatialRef = layer.GetSpatialRef()
spatialRef.ExportToWkt()
'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'
You can also use spatialRef.ExportToPrettyWkt()
,spatialRef.ExportToProj4()
,spatialRef.ExportToUSGS()
and many other formats.
First feature of the shapefile
feature = layer.GetFeature(0)
feature.ExportToJson()
'{"geometry": {"type": "Polygon", "coordinates": [[[5.826429692987699, 50.63093772365397], [5.830982302422351, 50.62928355089628], [5.826407932565759, 50.6268451632606], [5.82334832264974, 50.62941225500874], [5.826429692987699, 50.63093772365397]]]}, "type": "Feature", "properties": {"id": null}, "id": 0}'
And the point coordinates of the Polygon (WGS84 in degrees)
import json
json.loads(feature.ExportToJson())['geometry']['coordinates']
[[[5.826429692987699, 50.63093772365397], [5.830982302422351, 50.62928355089628], [5.826407932565759, 50.6268451632606], [5.82334832264974, 50.62941225500874], [5.826429692987699, 50.63093772365397]]]
2) With the same shapefile in a projected coordinate system (in meters)
infile = ogr.Open("aproj.shp")
layer = infile.GetLayer()
feature = layer.GetFeature(0)
json.loads(feature.ExportToJson())['geometry']['coordinates']
[[[253122.92278611325, 147711.88454888575], [253448.57840302447, 147534.25421241205], [253130.3240500753, 147256.7068115687], [252908.28612947493, 147537.9548443528], [253122.92278611325, 147711.88454888575]]]
3) For the conversion between the two geometries, I need to reproject the shapefile (degrees to meters) with osgeo.osr
or Pyproj (there are many examples in GIS SE).
4) Instead of using osgeo.ogr why don't use the more "Pythonic" Fiona (another Python wrapper of the OGR library)
import fiona
file = fiona.open("aWGS84.shp")
spatialRef = file.crs
spatialRef
{'init': u'epsg:4326'}
Fiona use Python dictionaries for all (GeoJson format), therefore the first feature is obtained by
file.next()
{'geometry': {'type': 'Polygon', 'coordinates': [[(5.826429692987699, 50.63093772365397), (5.830982302422351, 50.62928355089628), (5.826407932565759, 50.6268451632606), (5.82334832264974, 50.62941225500874), (5.826429692987699, 50.63093772365397)]]}, 'type': 'Feature', 'id': '0', 'properties': OrderedDict([(u'id', None)])}