I have a list of more than one hundred CRS defenitions in PROJ4 format in a plain text file (csv, tsv or txt). I'd like to know if there is any way of adding them into QGIS database at once. The "Custom CRS" dialog offers only manual adding of CRS into the app.

QGIS 3.14.1


You may try to adapt a recipe I've already provided in another answer to programmatically adding custom projections

my_new_projection = QgsCoordinateReferenceSystem("PROJ:+proj=ortho +lat_0=51.470129 +lon_0=-0.452751 +x_0=0 +y_0=0 +a=1188300 +b=1188300 +units=m +no_defs")

my_new_projection.saveAsUserCrs('my_new_projection name') # Save the definition so can be reusable later

What is missing in above answer is the fact, you should loop on CSV/txt file content using Python (not geo-related, pure programing). For this intent, look at https://realpython.com/python-csv/#parsing-csv-files-with-pythons-built-in-csv-library

The other solution can be to manipulate SQlite srs.db, the internal QGIS database for managing crs/srs. You can find it path on your computer by running in Python QGIS console this code QgsApplication.srsDatabaseFilePath().

For projections, you should look at QgsCoordinateReferenceSystem class API doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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