2

I got sample shapefiles with the following *prj file content:

PROJCS["RGF93_Lambert_93",GEOGCS["GCS_RGF_1993",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",700000.0],PARAMETER["False_Northing",6600000.0],PARAMETER["Central_Meridian",3.0],PARAMETER["Standard_Parallel_1",44.0],PARAMETER["Standard_Parallel_2",49.0],PARAMETER["Latitude_Of_Origin",46.5],UNIT["Meter",1.0]]

Trying to convert the projection using the shp2pgsql command shp2pgsql -s 4326 kept the original projection and didn't convert it as requested.

I also check spatial_ref_sys table srtext field for similar known projection unsuccessfully.

How can I convert it to WGS 84 projection?

nmtoken
  • 13,355
  • 5
  • 38
  • 87
OLS
  • 197
  • 1
  • 11

3 Answers3

8

The shp2pgsql tool is used to load data into PostGIS. It is not meant for transforming projections. The -s flag of the command just tells shp2pgsql the SRID of your source data. It doesn't transform the projection at all. You can reproject it before you load it to PostGIS or after.

To transform the projection before you load it to PostGIS, you can use GIS tools like QGIS or GDAL.

To change the projection after loading the data into PostGIS, you can use the ST_Transform command.

Btw, you have to give the shp2pgsql tool the shape file's actual projection. According to Spatialreference.org, your shape file's SRID is 2154. You might want to import it properly this time, using -s 2154 instead of -s 4326 and then perform the ST_Transform on PostGIS.

Of the two options, I think it would be simpler to convert the file before loading it to PostGIS. That way, you won't have to mess around with the spatial database much.


On Identifying your shape file's projection

Stumbled upon prj2EPSG from after reading this thread. Pasted your definition on it and got the following results:

  • 2154 - RGF93 / Lambert-93
  • 3944 - RGF93 / CC44
  • 3949 - RGF93 / CC49

You might want to investigate those three.

R.K.
  • 17,405
  • 3
  • 59
  • 110
  • thanks for your assistance. I cannot run the st_transform since the original projection is unknown to postgis. – OLS Sep 20 '12 at 21:29
  • updated my answer. You might want to import it properly this time. – R.K. Sep 20 '12 at 21:45
  • how can I dig from the prj file the projection name / SRID?
  • I ran shp2pgsql -s 104107 [file.shp] > [file.sql] and than tried to upload it to db. It fails. stating invalid SRID
  • – OLS Sep 20 '12 at 21:54
  • I just looked at the data you posted. Yours has GCS_RGF_1993. I searched it on Google and then I got a result at http://spatialreference.org – R.K. Sep 20 '12 at 21:56
  • Just found a new tool. You might want to check my answer again. – R.K. Sep 20 '12 at 22:11
  • thanks. reading the prj file again, it's the first option. 2154 - RGF93 / Lambert-93. converted it and it works fine now. – OLS Sep 20 '12 at 22:26
  • FYI, any SRID that's greater than 32766 is not EPSG, but defined by another authority. Esri (me) tends to use numbers in the 100k range. – mkennedy Sep 21 '12 at 16:09
  • 1
    From at least PostGIS v2.0.0 you can specify a source and a target SRID in shp2pgsql command line tool (somehow not in the GUI yet). Just run "shp2pgsql -?" to display your version and options. It says: "-s [:] Set the SRID field. Defaults to 0. Optionally reprojects from given SRID (cannot be used with -D)." – der Michi Jul 18 '13 at 12:13
  • As @Michi states there's more functionality in postgis v2, here's a nice cheatsheet of the options: http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg – claytonrsh Feb 27 '16 at 20:37