Is it possible to programmatically lookup a projection's name (e.g. Albers Equal-Area) from its EPSG using pyproj?

I see pyproj.pj_list, but it does not contain a mapping to the EPSG.

up vote 5 down vote accepted

List pj_list gives you at least projections the proj command understands. The EPSG context in the proj.4 biotop is a simple file based "DATABASE" that connects ONLY EPSG number entries (KEYS) with initialization params of the tool proj. You will find the data in the file

 /usr/share/proj/epsg

if you use proj.4 and one of it's bindings in LINUX.

Each entry has an EPSG key and a set of proj params. It looks like this. A line beginning with # is a comment line and a line beginning with <NUMBER> is an EPSG data entry. Some example lines:

$ less /usr/share/proj/epsg

Output (..shorted)

...
# NAD83 / Texas Centric Albers Equal Area
<3083> +proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=6000000 +datum=NAD83 +units=m +no_defs  <>
# NAD83(HARN) / Texas Centric Lambert Conformal
<3084> +proj=lcc +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=5000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs  <>
# NAD83(HARN) / Texas Centric Albers Equal Area
<3085> +proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=6000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs  <>
# NAD83 / Florida GDL Albers
<3086> +proj=aea +lat_1=24 +lat_2=31.5 +lat_0=24 +lon_0=-84 +x_0=400000 +y_0=0 +datum=NAD83 +units=m +no_defs  <>
...

You can use LINUX command line programs like grep to retrieve your info by screening the parameter +proj=aea (aea = Albers Equal Area) and the comments above the EPSG definition.

grep -B 1 'proj=aea' /usr/share/proj/epsg 

Output (..shorted)

# NAD27 / Alaska Albers
<2964> +proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD27 +units=us-ft +no_defs  <>
--
# NAD83 / BC Albers
<3005> +proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +datum=NAD83 +units=m +no_defs  <>
--
# NAD83 / Texas Centric Albers Equal Area
<3083> +proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=6000000 +datum=NAD83 +units=m +no_defs  <>
--

And the parameter meaning of grep is:

grep -B 1 PATTERN FILE
      |       |     |
      |       |     +--- the file you want to screen ../usr/share/proj/epsg
      |       +--- the search pattern ..a line containing 'proj=aea'
      +--- show me one line before the pattern match happened ..usually the comment

You can write a small wrapper in python if you SHELL OUT the grep stuff in combination with the pj_list and build your own dictionary. Here a small "dirty" example (..for the shell out part only):

#!/usr/bin/python
import os

# Command
cmd  = 'grep -B 1 "proj=aea" /usr/share/proj/epsg'

# Shell out and handler
hnd  = os.popen(cmd)

# line to parse
ln   = "--"

# variable for comment (line before)
cmt  = ""

# variable for epsg definition
epsg = ""

# dict of found stuff
found = {}

# iterate lines in handler
while ln:

  # real on line
  ln = hnd.readline()

   # have a comment
  if ln.startswith('#'):
      cmt = ln

  # have a epsg definition 
  if ln.startswith('<'):

      # grab only the key 
      epsg = ln.split(' ')[0]

      # store in dict
      found[epsg]=cmt

# close handle after iteration 
hnd.close()

# show the results    
for epsg in sorted(found):
    print epsg, found[epsg]
  • Wow thanks for this insight. A bit more involved than I was hoping and am also looking for a cross-platform solution (i.e. windows support). Looks like pyproj might simply not be my solution. thanks for you help and detailed answer – bcollins Feb 8 '16 at 20:33
  • You can use a unix/posix like environment like cygwin in windows. Look at cygwin.com for a nearly perfect POSIX like environment or unxutils.sourceforge.net if want to stay in MS environment and try to find the location of the epsg file. – huckfinn Feb 9 '16 at 13:55
  • Hey thanks, yes I'm familiar with cygwin and its great. – bcollins Feb 9 '16 at 14:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.