12

I downloaded the county files from:

http://www.census.gov/cgi-bin/geo/shapefiles2011/main

I cannot figure out what SRID to use with them. When I am trying to generate a class file from ./manage.py ogrinspect ..., I get an SRID of -1 in the polygon field. I don't think that this is right.

GDAL gave me the Proj4 of +proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs.

I know an SRID of -1 means unknown. Wouldn't that make my geometries useless? How can I figure out what SRID to use?

I am really new to GIS. I already miss the days when the Earth was flat.

This may also be useful:

SELECT PostGIS_full_version();
                                         postgis_full_version                                          
-------------------------------------------------------------------------------------------------------
 POSTGIS="1.5.3" GEOS="3.2.2-CAPI-1.6.2" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.8" USE_STATS
(1 row)

>>> import django
>>> django.VERSION
(1, 4, 0, 'final', 0)

2 Answers 2

20

The first step to determining the correct projection of any layer, is to find the projection information, if any, that came with your layer. In the case of a Shapefile, like what you downloaded from Census.gov, that information is contained in a .prj file, short for Projection.

Here are the contents of the projection file from the census data:

GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

The key parts of this, are the first word GEOGCS means Geographic Coordinate System, the string DATUM: D_North_American_1983, SPHERIOD: GRS_1980, and the last part UNIT: Degree.

These easily match up to the Proj4 definition that you received: +proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs

You can see that the datum and ellipsoid, match up to the datum and spheriod in the ".prj". The longlat means Longitude/Latitude, which is measured in Units of Degrees, which matches the ".prj" file.

There are "no defs" because no additional information is necessary to identify the Geographic Coordinate System.

A site to search for spatial references is: SpatialReference.org

The Geographic Coordinate System in NAD 83 is hard to come up with directly, because it is a part of many other projections.

To make it easier, the one you need is EPSG 4269.

This link presents the spatial reference information in a number of different formats. The one specifically for PostGIS is:

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 94269, 'epsg', 4269, '+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs ', 'GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]]');

To address your last point regarding the SRID = -1, I think it is important to test your data before you assume they are useless. Try to bring it up in some GIS software, like QGIS, or ArcGIS. Look at the coordinates that are shown as you move the cursor around. If you see familiar ranges of numbers, like y = 0 – +90 and x = -180 – +180, you should recognize these as Latitude/Longitude. Beginning to recognize the coordinate ranges that occur in the common projections and coordinate systems in your area will help you greatly as you move forward in your career.

If you are interested in learning more about projections and coordinate systems, this is a fantastic reference: A Working Manual (PDF) - John P. Snyder

7
  • I did realize, that I may have asked the wrong question. I asked for fish when I should have asked how to fish. If I search for 'GRS80 NAD83' at SpatialReference.org, I get one result that does not look correct. --- The link you gave for EPSG 4269 has the OpenLayers map display with a bounding box around most of Asia and North Africa. Is this correct or even significant?
    – kzh
    Commented Jun 19, 2012 at 22:03
  • @kzh - I honestly do not know why it is showing that bounding box. It is not significant though. The details contained within the spatial reference are what count, and they are correct. Commented Jun 19, 2012 at 22:06
  • The degree is slightly off for some reason - why would that be? spatialreference.org has a more accurate listing here: spatialreference.org/ref/sr-org/6867 , which doesn't exist as an srid in my spatial_ref_sys table. Commented Jun 6, 2013 at 18:56
  • @GetSpatial - Why did you use 94269 as the SRID instead of 4269? (since 4269 is the EPSG identifier for NAD 83)
    – neubert
    Commented Jan 1, 2016 at 21:47
  • 1
    @GetSpatial - From Mr Butler at spatialreference.org "all postgis IDs are prefixed with 9 to ensure that they don't collide with existing postgis IDs."
    – kttii
    Commented Jul 6, 2016 at 13:31
3

@Get Spatial is right and it couldnt have been better answer to this question. in addition to him you can check out spatial_ref_sys before adding any spatial reference.

SELECT * FROM
       spatial_ref_sys WHERE auth_srid = 4269;

probably you will take sth like this:

SRID  | AUTH_NAME  | AUTH_SRID  | SRTEXT
------+------------+------------+-------
4269  |   EPSG     |   1624     | <big SRTEXT string>

SRTEXT = GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 
         1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],
         PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,
         AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]]

PROJ4TEXT = +proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs

Spatial_ref_sys is merely a table of known coordinate systems keyed by their SRID. you cabn get more info here...

  • srid: The numeric SRID. This should be the table’s primary key.
  • auth_name: An authority name as a string. This is set if this coordinate system is specified by an outside authority such as EPSG.
  • auth_srid: The numeric ID of the coordinate system in the above authority’s catalog.
  • srtext: The Well-Known-Text (WKT) representation of the coordinate system (as we described in part 4).
  • proj4text: The Proj4 representation of the coordinate system.

and last thing is that for loading it to database use this command:

shp2pgsql -c -D -s 4269 -I tl_2011_02_anrc.shp myschema.mytable > mysql.sql
psql -d mydb -f mysql.sql

i hope it helps you....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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