Search code examples
djangopython-3.xgeodjango

Geodjango create a new SRID


Hello guys I've been trying to add a shapefile but I'm facing some difficulties since my country's coordinate system isn't part of the gdal library. How can i create a new SRID.I have already created the srs and defined the spatial reference system in postgis.


Solution

  • PostGIS stores Spatial reference systems in a table called spatial_ref_sys. Django has a model to access the data in this table called SpatialRefSys, but it's not documented.

    Also not documented is the utility function add_srs_entry(), which takes an SpatialReference instance as first argument, which can be defined from a PROJ.4 string.

    So something like this should work:

    from django.contrib.gis.utils.srs import add_srs_entry
    from django.contrib.gis.gdal import SpatialReference
    
    srs = SpatialReference('''...PROJ.4 string...''')
    add_srs_entry(srs)
    

    Alternatively, you can add the entry using a database management tool