How do you know what SRID to use for a shp file?

42.6k views Asked by At

I am trying to put a SHP file into my PostGIS database, the the data is just a little off. I think this is because I am using the wrong SRID. The contents of the PRJ file are as follows:

GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]]

What SRID does this correlate to? And more generally, how can I look up the SRID based on the information found in the PRJ file? Is there a lookup table somewhere that lists all SRID's and their 'geogcs' equivalents?

The data imported using srid=4269 and 4326 were the exact same results.

Does this mean I'm using the wrong SRID, or is this just expected margin of error?

The shp file is from here.

6

There are 6 answers

0
James Schek On BEST ANSWER

To elaborate on synecdoche's answer, the SRID is sometimes called an "EPSG" code. The SRID/EPSG code is a defacto short-hand for the Well-Known-Text representations of projections.

You can do a quick search on the SRID table to see if you can find an exact or similar match:
SELECT srid, srtext, proj4text FROM spatial_ref_sys WHERE srtext ILIKE '%BLAH%'

Above was found at http://www.bostongis.com/?content_name=postgis_tut01.

You can also search on spatialreference.org for these kinds of things. The search tool is primitive so you may have to use a Google search and specify the site, but any results will show you the ESRI PRJ contents, the PostGIS SQL INSERT, and a bunch of other representations.

I think your PRJ is at: http://spatialreference.org/ref/sr-org/15/

0
Mike T On

Use GDAL's OSR Python module to determine the code:

from osgeo import osr

srsWkt = '''GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]]'''

# Load in the projection WKT
sr = osr.SpatialReference(srsWkt)

# Try to determine the EPSG/SRID code
res = sr.AutoIdentifyEPSG()
if res == 0: # success
    print('SRID=' + sr.GetAuthorityCode(None))
    # SRID=4269
else:
    print('Could not determine SRID')
0
rburhum On

Go and download the GDAL utilities , the ogrinfo (which would spit the projection information) and ogr2ogr utilities are invaluable.

James gave already a link to spatialreference.org. That helps to find spatial reference information... I assume you did load the spatial_ref_sys.sql when you prepared your postgis instance.

And to be honest, I don't think the problem is in the PostGIS side of things.

I usually keep my data in different SRIDs in my PostGIS dbs. However, I always need to project to the output SRS. You are showing OpenStreetMap pre-rendered tiles, and I bet they have been drawn using SRID 900913 (the Google Map's modified mercator projection that now everyone uses to render).

My recommendation to you is:

1- Set the right projection in the OpenLayers code which matches whatever tiles you are reading from.

2.- Keep the data in the database in whatever SRID you want (as long as it is correct of course).

3.- Make sure the server you are using to generate the images from your data (ArcGIS Server, Mapserver, GeoServer or whatever it is) is reprojecting to that same SRS.

Everything will match.

Cheers

0
synecdoche On

The data seems to be NAD83, which has an SRID of 4269. Your PostGIS database has a spatial_ref_sys table which is the SRID lookup table.

If the data looks the same with an SRID of 4269 (NAD83) and 4326 (WGS84), then there's something wrong.

0
Doug On

Be sure to take a look at: http://www.epsg-registry.org/

Use the Query by Filter option and enter: North American Datum 1983.

This yields -> EPSG:6269.

Hope this works for you.

4
Nelson On

Prj2EPSG is a small website aimed at exactly this problem; paste in the PRJ contents and it does its best to find a matching EPSG. They also have a web service API. It's not an exact science. They seem to use Lucene and the EPSG database to do text searches for matches.