Skip to main content
deleted 73 characters in body
Source Link
onakua
  • 690
  • 4
  • 10

You can also do this in one line using gdal.Info as so:

epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert (which is also a legit way of getting the EPSG; not really a workaround). It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.

You can also do this in one line using gdal.Info as so:

epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert (which is also a legit way of getting the EPSG; not really a workaround). It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.

You can also do this in one line using gdal.Info as so:

epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert. It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.

added 606 characters in body
Source Link
onakua
  • 690
  • 4
  • 10

You can also do this in one line using gdal.Info as so:

ds = gdal.Open(path)
epsg = int(gdal.Info(dsinput, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert (which is also a legit way of getting the EPSG; not really a workaround). It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.

You can also do this in one line using gdal.Info as so:

ds = gdal.Open(path)
epsg = int(gdal.Info(ds, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

You can also do this in one line using gdal.Info as so:

epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert (which is also a legit way of getting the EPSG; not really a workaround). It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take. input may be a datasource, valid filepath, or anything within gdal's extensive virtual file systems, which allows this method to accommodate a large number of potential use cases.

Source Link
onakua
  • 690
  • 4
  • 10

You can also do this in one line using gdal.Info as so:

ds = gdal.Open(path)
epsg = int(gdal.Info(ds, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])