2

I have a series of shape files that I am trying to convert and enter into a postgis database so that I can pull the data out as GeoJSON but I am having troubles getting the data to enter with the correct coordinate values.

My source files say they are:

Datum:  NAD 83, CSRS98
Projection: UTM Extended Zone 13

And when I run gdalsrsinfo against the .prj file, I get the following:

PROJ.4 : '+proj=utm +zone=13 +ellps=GRS80 +units=m +no_defs '

OGC WKT :
PROJCS["NAD_1983_CSRS98_UTM_Zone_13N",
GEOGCS["GCS_North_American_1983_CSRS98",
    DATUM["NAD83_Canadian_Spatial_Reference_System",
        SPHEROID["GRS_1980",6378137.0,298.257222101]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",500000.0],
PARAMETER["False_Northing",0.0],
PARAMETER["Central_Meridian",-105.0],
PARAMETER["Scale_Factor",0.9996],
    PARAMETER["Latitude_Of_Origin",0.0],
    UNIT["Meter",1.0]]

Using that information, I pulled up http://georepository.com/crs_4140/NAD83-CSRS98.html and see the ID is listed at 4140.

So I ran

shp2pgsql -s 4140 shapefile > output.sql

But when I import the result into postgis, my coordinates are all out of sorts:

SELECT ST_AsGeoJSON(geom) FROM shapefile_import;
{"type":"MultiPolygon","coordinates":[[[[535472.058,5466281.22],[535069.83,5466278.55],[535068.17,5466514.07],[535068.03,5466534.18],[535066.992,5466680.332],[535064.14,5467082.11],[535061.3,5467483.903],[535058.46,5467885.69],[535460.67,5467887.69],[535862.87,5467889.69],[536265.07,5467891.69],[536667.28,5467893.69],[536669.945,5467492.576],[536672.61,5467091.46],[536675.278,5466690.345],[536677.54,5466350.32],[536677.81,5466310.46],[536677.95,5466289.23],[536276.118,5466286.56],[535874.28,5466283.89],[535472.058,5466281.22]]]]}

Can anyone point me in the right direction? I have been using http://geojsonlint.com to validate.

Edit 1

JGH's answer is correct, I was using the wrong ID in my conversion. It should have been 2151.

I ran now run SELECT ST_AsGeoJSON(ST_Transform(geom,4326)) FROM shapefile_import;

  • what do you mean "out of sorts" those look like plausible UTM coordinates to me – Ian Turton May 28 '18 at 16:41
  • As documented AsGeoJSON postgis.org/docs/ST_AsGeoJSON.html creates old-school GeoJSON that supports different coordinate systems geojson.org/geojson-spec.html. You can validate such GeoJSON in another site geojson.io. However, your GeoJSON is missing the crs member and can't be reprojected right. – user30184 May 28 '18 at 17:37
  • @user30184 is there a way to output an the "new" format in that case? I am looking to overlay these onto Google Maps API with addGeoJson which requires the inclusion of a Feature or FeatureCollection – mgabe May 28 '18 at 17:41
  • It should be close to enough if you translate into epsg:4326 and omit crs member. – user30184 May 28 '18 at 18:07
  • Correction: geojson.io can't be used for validating old school geojson. I have not found any site yet that does that. – user30184 May 29 '18 at 5:07
2

The SRID 4140 is the wrong one, as it is in lat-long:

+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs

The SRID for the UTM zone you are looking for is 2151:

+proj=utm +zone=13 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
  • Aha, that makes sense. I am now able to perform a ST_AsGeonJSON(ST_Transform(geom, 4326)) to get my lnglat values. – mgabe May 28 '18 at 17:37
  • @user30184 correct, typo. – mgabe May 28 '18 at 17:40
1

Geojson linter uses wgs84 (EPSG:4326) wystem. Your is in 4140.

The coordinate reference system for all GeoJSON coordinates is a
geographic coordinate reference system, using the World Geodetic
System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units
of decimal degrees.

Your query should be

SELECT ST_AsGeoJSON(ST_Transform(geom,4326)) FROM shapefile_import;

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.