[GRASS-dev] [GRASS GIS] #3750: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new location

#3750: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new
location
---------------------------------------+-------------------------
Reporter: rshepard | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Keywords: locaton wizard, .prj file | CPU: x86-32
Platform: Linux |
---------------------------------------+-------------------------
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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new
location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------
Changes (by hellik):

* Attachment "location_wizard.PNG" added.

location wizard - read prj file

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new
location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by hellik):

Replying to [ticket:3750 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): GUI location widget cannot read .prj file for new
location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by 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):
https://www.gdal.org/classGDALDataset.html#a9cb8585d0b3c16726b08e25bcc94274a

Perhaps g.proj could be updated accordingly?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by mmetz):

Replying to [comment:2 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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by mmetz):

Replying to [comment:4 mmetz]:
> Replying to [comment:2 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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by neteler):

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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by neteler):

Also the new r74074 works fine for me.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#3750: Grass 7.7.svn (r74061): CLI location creation: cannot read .prj file for
new location
-----------------------+---------------------------------------
  Reporter: rshepard | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.8.3
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: locaton wizard, .prj file
       CPU: x86-32 | Platform: Linux
-----------------------+---------------------------------------

Comment (by neteler):

Anything missing here?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3750#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>