[Qgis-user] how does QGIS generate the EPSG from a Shapefile?
Jorge Gustavo Rocha
jgr at di.uminho.pt
Sun Oct 28 16:27:48 PDT 2018
Hi Rodrigo,
GDAL (regular distribution) is not able to identify the EPSG code from
the *.prj string. This is a known limitation. This has been fix (see bug
[1]), but it requires additional files on your side.
Two options:
1) Download the files from:
https://trac.osgeo.org/gdal/raw-attachment/ticket/4345/epsg_ogc.wkt.gz
https://trac.osgeo.org/gdal/raw-attachment/ticket/4345/epsg_ogc_simple.wkt.gz
https://trac.osgeo.org/gdal/raw-attachment/ticket/4345/epsg_esri.wkt.gz
2) You can create the files by yourself running the script
gen_epsg_wkt.sh (available on the #4345 ticket). Change the path to the
existing files. In my GDAL installation, I had to change to:
gcs_epsg=`cat /usr/share/gdal/2.2/gcs.csv | (...)`
pcs_epsg=`cat /usr/share/gdal/2.2/pcs.csv | (...)`
Move/copy the files to your GDAL folder (in my case it is
/usr/share/gdal/2.2)
Then you can use:
gdalsrsinfo -e deinfo_cemiterios.shp
The result will be:
jgr at zoe:~/tmp$ gdalsrsinfo -e deinfo_cemiterios.shp
Warning 1: EPSG detection is experimental and requires new data files
(see bug #4345)
EPSG:29193
PROJ.4 : '+proj=utm +zone=23 +south +ellps=aust_SA
+towgs84=-66.87,4.37,-38.52,0,0,0,0 +units=m +no_defs '
OGC WKT :
PROJCS["SAD69 / UTM zone 23S",
GEOGCS["SAD69",
DATUM["South_American_Datum_1969",
SPHEROID["GRS 1967 Modified",6378160,298.25,
AUTHORITY["EPSG","7050"]],
TOWGS84[-66.87,4.37,-38.52,0,0,0,0],
AUTHORITY["EPSG","6618"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4618"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",-45],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",10000000],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","29193"]]
Now you can use gdalsrsinfo to identify the CRS. If you need to use this
for scripting, it is easier.
Best regards,
Jorge
[1] https://trac.osgeo.org/gdal/ticket/4345
Às 18:15 de 28/10/18, Rodrigo Mariano escreveu:
> Hello Jorge,
>
>
> When I used your command like, the ogr showed this message:
>
> "Layer name: DEINFO_CEMITERIOS
> Geometry: Polygon
> Feature Count: 42
> Extent: (317568.093609, 7361463.898064) - (357756.090027, 7412287.112520)
> Layer SRS WKT:
> PROJCS["SAD69_UTM_zone_23S",
> GEOGCS["GCS_SAD69",
> DATUM["South_American_Datum_1969",
> SPHEROID["GRS_1967_Modified",6378160,298.25]],
> PRIMEM["Greenwich",0],
> UNIT["Degree",0.017453292519943295]],
> PROJECTION["Transverse_Mercator"],
> PARAMETER["latitude_of_origin",0],
> PARAMETER["central_meridian",-45],
> PARAMETER["scale_factor",0.9996],
> PARAMETER["false_easting",500000],
> PARAMETER["false_northing",10000000],
> UNIT["Meter",1]]
> ID: Integer64 (10.0)
> NOME: String (60.0)
> AREA: Real (20.2)
> DEPADM: String (10.0)"
>
> When I opened the Shapefile with the QGIS, the software chose the EPSG
> 29193.
>
> But when I use the ogr2ogr to insert the Shapefile in my database, the
> OGR choose a strange EPSG.
> For that reason, I normally open the Shapefile with the QGIS and I pass
> explicitily the EPSG on ogr2ogr command line.
> Because of that I would like to know how the QGIS discover the EPSG
> given a .prj.
>
> The .prj of that Shapefile is:
>
> "PROJCS["SAD69_UTM_zone_23S",GEOGCS["GCS_SAD69",DATUM["D_South_American_1969",SPHEROID["GRS_1967_Truncated",6378160,298.25]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-45],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["Meter",1]]"
>
>
> Best Regards,
>
> Rodrigo
>
>
> On 25/10/2018 15:59, Jorge Gustavo Rocha wrote:
>> Oi Rodrigo,
>>
>> Can you run ogrinfo in the command line? Like:
>>
>> ogrinfo -al -so yourshape.shp
>>
>> This will tell you the CRS detected by ogr.
>>
>> ogr (and QGIS) uses the *.prj file. But there are known problems with
>> the WKT representation of CRS. Sometimes it is hard to know if two
>> different strings represents the same EPSG code.
>>
>> For that reason, QGIS also writes and additional *.qpj. When it is
>> present, QGIS uses this textual representation to compare it against its
>> database and it always work.
>>
>> But if you just have the *.prj along with the shapefile, both ogr and
>> QGIS might fail to detect the exact CRS.
>>
>> Please share one *.prj that ogr fails to associate with a known EPSG.
>>
>> Abraço,
>>
>> Jorge
>>
>> Às 13:27 de 25/10/18, Rodrigo Mariano escreveu:
>>> Hello everyone,
>>>
>>> I would like to know: how does QGIS generate the EPSG from a Shapefile?
>>>
>>> I ask this question, because I'm trying to upload a Shapefile by OGR,
>>> but the OGR doesn't
>>> insert the correct EPSG. So I need always open the Shapefile in QGIS to
>>> discover the
>>> EPSG before uploading it with OGR.
>>>
>>> Thanks in advance.
>>>
>>> Best Regards,
>>>
>>> Rodrigo
>>>
>>> _______________________________________________
>>> Qgis-user mailing list
>>> Qgis-user at lists.osgeo.org
>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> J. Gustavo
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
J. Gustavo
--
Jorge Gustavo Rocha
Departamento de Informática
Universidade do Minho
4710-057 Braga
Tel: +351 253604480
Fax: +351 253604471
Móvel: +351 910333888
skype: nabocudnosor
More information about the Qgis-user
mailing list