Opened 6 years ago

Last modified 5 years ago

#3750 new defect

Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for new location

Reported by: rshepard Owned by: grass-dev@…
Priority: normal Milestone: 7.8.3
Component: wxGUI Version: svn-trunk
Keywords: locaton wizard, .prj file Cc:
CPU: x86-32 Platform: Linux

Description

Trying to create a new location using a shapefile .prj. GRASS tells me it annot read the file using gdal.

Markus N. confirms this and recommends using the .shp file instead.

Setting the location's projection on the command line works, but not from the GUI. The 2019-02-09 thread has more details.

Attachments (1)

location_wizard.PNG (186.2 KB ) - added by hellik 6 years ago.
location wizard - read prj file

Download all attachments as: .zip

Change History (10)

by hellik, 6 years ago

Attachment: location_wizard.PNG added

location wizard - read prj file

in reply to:  description comment:1 by hellik, 6 years ago

Replying to rshepard:

Trying to create a new location using a shapefile .prj. GRASS tells me it annot read the file using gdal.

for me it works with the GUI location wizard; see attached screenshot to choose the option read projection from a .prj file.

Markus N. confirms this and recommends using the .shp file instead.

that's the option read projection from a georeferenced file.

Setting the location's projection on the command line works, but not from the GUI. The 2019-02-09 thread has more details.

isn't it the other way around?

CLI with .prj file doesn't work, but GUI with .prj file works.

comment:2 by neteler, 6 years ago

# write out user's WKT string as .prj file
echo 'PROJCS["NAD_1983_UTM_Zone_11N",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]' > bla.prj

# attempt to generate a new location from it:
grass77 -c bla.prj  ~/grassdata/mylocation
Starting GRASS GIS...
Creating new GRASS GIS location <mylocation>...
ERROR: ERROR 4: `bla.prj' not recognized as a supported file format.
ERROR: Unable to read georeferenced file <bla.prj> using GDAL library

I checked further and found a difference between g.proj and gdalsrsinfo opening files:

general/g.proj/input.c, line 271 : (inofficially: https://github.com/GRASS-GIS/grass-ci/blob/master/general/g.proj/input.c#L271)

        if ((gdal_ds = GDALOpen(geofile, GA_ReadOnly))) {

apps/gdalsrsinfo.cpp, line 306 https://github.com/OSGeo/gdal/blob/master/gdal/apps/gdalsrsinfo.cpp#L306

    poGDALDS = static_cast<GDALDataset *>(GDALOpenEx( pszInput, 0,
nullptr, nullptr, nullptr ));

It seems that GDALOpenEx() is more flexible concerning the input (it exists since GDAL 2.0): https://www.gdal.org/classGDALDataset.html#a9cb8585d0b3c16726b08e25bcc94274a

Perhaps g.proj could be updated accordingly?

comment:3 by hellik, 6 years ago

Summary: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new locationGrass 7.7.svn (r74061): CLI location creation: cannot read .prj file for new location

in reply to:  2 ; comment:4 by mmetz, 6 years ago

Replying to neteler:

# write out user's WKT string as .prj file
echo 'PROJCS["NAD_1983_UTM_Zone_11N",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]' > bla.prj

# attempt to generate a new location from it:
grass77 -c bla.prj  ~/grassdata/mylocation
Starting GRASS GIS...
Creating new GRASS GIS location <mylocation>...
ERROR: ERROR 4: `bla.prj' not recognized as a supported file format.
ERROR: Unable to read georeferenced file <bla.prj> using GDAL library

I checked further and found a difference between g.proj and gdalsrsinfo opening files:

general/g.proj/input.c, line 271 : (inofficially: https://github.com/GRASS-GIS/grass-ci/blob/master/general/g.proj/input.c#L271)

        if ((gdal_ds = GDALOpen(geofile, GA_ReadOnly))) {

apps/gdalsrsinfo.cpp, line 306 https://github.com/OSGeo/gdal/blob/master/gdal/apps/gdalsrsinfo.cpp#L306

    poGDALDS = static_cast<GDALDataset *>(GDALOpenEx( pszInput, 0,
nullptr, nullptr, nullptr ));

It seems that GDALOpenEx() is more flexible concerning the input (it exists since GDAL 2.0):

No, the trick is here: https://github.com/OSGeo/gdal/blob/a0e1932541cb4edc6d2e254d7af6f64cd0dc0806/gdal/apps/gdalsrsinfo.cpp#L334

If GDALOpenEx() fails, it checks if it is a *.prj file

in reply to:  4 comment:5 by mmetz, 6 years ago

Replying to mmetz:

Replying to neteler:

# write out user's WKT string as .prj file
echo 'PROJCS["NAD_1983_UTM_Zone_11N",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]' > bla.prj

# attempt to generate a new location from it:
grass77 -c bla.prj  ~/grassdata/mylocation
Starting GRASS GIS...
Creating new GRASS GIS location <mylocation>...
ERROR: ERROR 4: `bla.prj' not recognized as a supported file format.
ERROR: Unable to read georeferenced file <bla.prj> using GDAL library

I checked further and found a difference between g.proj and gdalsrsinfo opening files:

general/g.proj/input.c, line 271 : (inofficially: https://github.com/GRASS-GIS/grass-ci/blob/master/general/g.proj/input.c#L271)

        if ((gdal_ds = GDALOpen(geofile, GA_ReadOnly))) {

apps/gdalsrsinfo.cpp, line 306 https://github.com/OSGeo/gdal/blob/master/gdal/apps/gdalsrsinfo.cpp#L306

    poGDALDS = static_cast<GDALDataset *>(GDALOpenEx( pszInput, 0,
nullptr, nullptr, nullptr ));

It seems that GDALOpenEx() is more flexible concerning the input (it exists since GDAL 2.0):

No, the trick is here: https://github.com/OSGeo/gdal/blob/a0e1932541cb4edc6d2e254d7af6f64cd0dc0806/gdal/apps/gdalsrsinfo.cpp#L334

If GDALOpenEx() fails, it checks if it is a *.prj file

Please try trunk r74072

comment:6 by neteler, 6 years ago

Great, the change solves the cmd line issue! I compared the output of g.proj -w and testepsg, while not 100% identical it can be considered the same (I suppose that some EPSG laundery is going on).

I'd vote for backporting this.

comment:7 by neteler, 6 years ago

Also the new r74074 works fine for me.

comment:8 by neteler, 5 years ago

Milestone: 7.8.3

comment:9 by neteler, 5 years ago

Anything missing here?

Note: See TracTickets for help on using tickets.