TransWikia.com

Adding custom projection in GDAL 3

Geographic Information Systems Asked by eran on June 10, 2021

I want to add custom projection to the GDAL library version 3.

In earlier versions (with Ubuntu 18.04) we directly added the definition to the /usr/share/proj/epsg file

In GDAL 3 the files do not exist any more, how can we add the custom projection?

One Answer

The difference is in Proj library that is using different resource files since Proj version 6. The documentation is in https://proj.org/resource_files.html

A number of init files come pre-bundled with PROJ but it is also possible to add your own custom init files. PROJ looks for the init files in the directory listed in the PROJ_LIB environment variable.

As an example I added a new code 900900 by copying the last entry of the file "others.extra" in my PROJ_LIB directory.

#  Funny epsgish code for google mercator - you should really use EPSG:3857
#
<900913> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs <>
<900900> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs <>

Now GDAL recognized this new custom projection as +init=others.extra:900900as can be verified for example with gdalsrsinfo https://gdal.org/programs/gdalsrsinfo.html. Notice the syntax, epsg:900900 does not work.

gdalsrsinfo +init=other.extra:900900

PROJ.4 : +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs

OGC WKT2:2018 :
PROJCRS["unknown",
    BASEGEOGCRS["unknown",
        DATUM["unknown",
            ELLIPSOID["unknown",6378137,0,
                LENGTHUNIT["metre",1,
                    ID["EPSG",9001]]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8901]]],
    CONVERSION["unknown",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]]

You can save your custom projection into file "epsg" in the PROJ_LIB directory but you must still use the +init syntax +init=epsg:900900 and you'll get a warning Warning 1: +init=epsg:XXXX syntax is deprecated. It might return a CRS with a non-EPSG compliant axis order.

I think that EPSG definitions with only epsg: prefix are now searched from the proj.db database where they are stored from the official EPSG database. The infamous EPSG:900913 seems to be there as well as some sort of extra in the table "projected_crs". You can check that with any SQLite database client.

select * from projected_crs where code=900913;
result:
EPSG    900913  Google Maps Global Mercator NULL    NULL    EPSG    4499    EPSG    4326    EPSG    3856    EPSG    3544    NULL    1

Because of that GDAL finds epsg:900913 even without +init

gdalsrsinfo epsg:900913

PROJ.4 : +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs

OGC WKT2:2018 :
PROJCRS["Google Maps Global Mercator",
...

If you want to add new custom, or fake, epsg codes and use them just as you have used to do then you should edit the proj.db database. However, I would not recommend to do it. Hopefully the +init syntax will work for you.

Answered by user30184 on June 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP