I want to list all EPSG codes from the new PROJ.6 tool in form of proj.4
strings. Is there a tool / SQL script to replicate the former /usr/share/proj/epsg
file from the SQLite3 proj.db
?
1 Answer
You can use Python for this purpose
Install the Python lib
# use version 2.4.2 as it install a version 6 of proj behind the scene
python3 -m pip install pyproj==2.4.2 pyproj
Then, run the following Python script
import os
import pyproj
all_epsg_crs_code = pyproj.get_codes('EPSG', 'CRS')
# Be aware that with to_proj4 usage you will get below warning
# UserWarning: You will likely lose important projection information when
# converting to a PROJ string from another format. See:
# https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
with open('/tmp/epsg', 'w') as input_file:
for i in all_epsg_crs_code:
my_proj = pyproj.CRS("epsg:{}".format(i))
old_epsg_string_format = """# {}{}<{}> {} <>""".format(
my_proj.name,
os.linesep,
i,
my_proj.to_proj4()
)
input_file.write(old_epsg_string_format)
You may want to set the path to your proj version content using https://pyproj4.github.io/pyproj/dev/installation.html#envvar-PROJ_DIR as by default Pyproj install it own binary/lib of proj.
-
Thank you, I will try your code snippet. Have you an idea, why the description of SRS goes forward to much more complicated WKT notation. In terms of comandline usage like in the proj.4 notation to the WTK one is not handy anymore.– huckfinnCommented Feb 18, 2021 at 0:06
-
1Already mentioned in the code snippet but here the clickable link proj.org/…. As I do not need projections with specific parameters, proj.4 or WKT are the same for me. Can't understand your pain in this case, just sympathize Commented Feb 18, 2021 at 0:15
-
1Direct transformations between datums aren't possible with Proj.4 since the definitions can be ambiguous. That's one of the main reasons for the deprecation of proj.4– JonasVCommented Feb 18, 2021 at 9:11
-
Yes I've scrolled through the code version 6 and 7 and since version 5, a lot of code refactoring is done, including new UTM transformation features. Code improvements are fine, but I'm a fan of breaking of long-term running legacy code by adding features or changing the behaviour of the complete tool set. If you check the code, it is planed that version 8 the proj.4 strings will be deprecated. Pitty is that, new code breaks the UNIX philosophy en.wikipedia.org/wiki/Unix_philosophy. The larger form of SRS definitions breaks "Interactive use instead of batch processing." for example.– huckfinnCommented Mar 7, 2021 at 22:41