[GRASS-dev] [GRASS GIS] #2140: m.proj does not handle cs2cs failure

#2140: m.proj does not handle cs2cs failure
--------------------------------+-------------------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Keywords: m.proj, cs2cs | Platform: All
      Cpu: All |
--------------------------------+-------------------------------------------
When I input wrong proj strings to `m.proj` it calls `cs2cs` which fails
and `m.proj` does not handle its error correctly.

To test (you need to have `test.txt` with any content):

{{{
m.proj input=test.txt proj_out="bla bla bla" proj_in="another bla bla bla"
}}}

The error message is:

{{{
Rel. 4.8.0, 6 March 2012
<cs2cs>:
projection initialization failure
cause: unknown projection id
program abnormally terminated
Traceback (most recent call last):
   File "/home/vasek/dev/grass/trunk_clang/dist.i686-pc-linux-
gnu/scripts/m.proj", line 292, in <module>
     main()
   File "/home/vasek/dev/grass/trunk_clang/dist.i686-pc-linux-
gnu/scripts/m.proj", line 271, in main
     x, y = xy.split('\t')
ValueError: need more than 1 value to unpack
}}}

I haven't investigated that but checking return code is probably enough.

''What is the correct Trac component for this ticket?''

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

#2140: m.proj does not handle cs2cs failure
--------------------------------+-------------------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Keywords: m.proj, cs2cs | Platform: All
      Cpu: All |
--------------------------------+-------------------------------------------

Comment(by wenzeslaus):

In the current version (after r59228) the tests
{{{
echo "111 111" > test.txt
m.proj input=test.txt proj_out="bla bla bla" proj_in="another bla bla bla"
}}}
outputs
{{{
Rel. 4.8.0, 6 March 2012
<cs2cs>:
projection initialization failure
cause: no arguments in initialization list
program abnormally terminated
ERROR: Using from definition:
}}}
which is much better than traceback but still it does not say what is the
problem and there is the strange "ERROR: Using from definition:"

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

#2140: m.proj does not handle cs2cs failure
---------------------------------+---------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Resolution: | Keywords: m.proj, cs2cs
       CPU: All | Platform: All
---------------------------------+---------------------------

Comment (by jrobparsons):

I think we need to verify the input arguments before the cs2cs.exe tool is
called.

I played with the '-e string' option, but the error messages generated by
cs2cs are not suppressed. The documentation
(https://trac.osgeo.org/proj/wiki/man_cs2cs) for the -e option talks about
using the -b, -i, or -o options to return a value. These options appear to
be invalid.

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

#2140: m.proj does not handle cs2cs failure
---------------------------------+---------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Resolution: | Keywords: m.proj, cs2cs
       CPU: All | Platform: All
---------------------------------+---------------------------

Comment (by neteler):

(un)related:

Even Rouault wrote in the proj ML on Jul 10, 2015:
>
> https://pypi.python.org/pypi/pyproj/ might be a better option for using
proj from Python.

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

#2140: m.proj does not handle cs2cs failure
---------------------------------+---------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Resolution: | Keywords: m.proj, cs2cs
       CPU: All | Platform: All
---------------------------------+---------------------------

Comment (by jrobparsons):

Studying the pyproj wrapper now.

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

#2140: m.proj does not handle cs2cs failure
---------------------------------+---------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Resolution: | Keywords: m.proj, cs2cs
       CPU: All | Platform: All
---------------------------------+---------------------------

Comment (by jrobparsons):

This is interesting...

Output from GRASS GUI Command Console
----------------------------------------------------

(Thu Jul 30 20:38:52 2015)
m.proj input=test.txt proj_out=bla bla bla proj_in=another bla bla bla
Rel. 4.8.0, 6 March 2012
<cs2cs.EXE>:
projection initialization failure
cause: Unknown error
program abnormally terminated
ERROR: Using from definition:
(Thu Jul 30 20:38:54 2015) Command finished (1 sec)

Output from GRASS Command Line
----------------------------------------------------

C:\>m.proj input=test.txt proj_out=bla bla bla proj_in=another bla bla bla

Description:
  Converts coordinates from one projection to another (cs2cs frontend).

Keywords:
  miscellaneous, projection

Usage:
  m.proj.py [-iodec] [coordinates=east,north] [input=name] [output=name]
    [separator=character] [proj_in=string] [proj_out=string] [--overwrite]
    [--help] [--verbose] [--quiet] [--ui]

Flags:
   -i Use LL WGS84 as input and current location as output projection
   -o Use current location as input and LL WGS84 as output projection
   -d Output long/lat in decimal degrees, or other projections with many
decimal places
   -e Include input coordinates in output file
   -c Include column names in output file
  --o Allow output files to overwrite existing files
  --h Print usage summary
  --v Verbose module output
  --q Quiet module output
  --ui Force launching GUI dialog

Parameters:
   coordinates Input coordinates to reproject
         input Name of input coordinate file
                  '-' for standard input
        output Name for output coordinate file (omit to send to stdout)
     separator Field separator (format: input[,output])
                  Special characters: pipe, comma, space, tab, newline
                 default: pipe
       proj_in Input projection parameters (PROJ.4 style)
      proj_out Output projection parameters (PROJ.4 style)

ERROR: Sorry <bla> is not a valid option
ERROR: Sorry <bla> is not a valid option
ERROR: Sorry <bla> is not a valid option
ERROR: Sorry <bla> is not a valid option
ERROR: Sorry <bla> is not a valid option

C:\>

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2140#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS GIS, commonly referred to as GRASS (Geographic Resources Analysis Support System), is a free and open source Geographic Information System (GIS) software suite used for geospatial data management and analysis, image processing, graphics and maps production, spatial modeling, and visualization. GRASS GIS is currently used in academic and commercial settings around the world, as well as by many governmental agencies and environmental consulting companies. It is a founding member of the Open Source Geospatial Foundation (OSGeo).

#2140: m.proj does not handle cs2cs failure
---------------------------------+---------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.0
Component: Projections/Datums | Version: svn-trunk
Resolution: | Keywords: m.proj, cs2cs
       CPU: All | Platform: All
---------------------------------+---------------------------

Comment (by neteler):

Replying to [comment:5 jrobparsons]:
> C:\>m.proj input=test.txt proj_out=bla bla bla proj_in=another bla bla
bla
...
> ERROR: Sorry <bla> is not a valid option
> ERROR: Sorry <bla> is not a valid option
...

Note that you need to quote the "bla bla..", otherwise the parser will
interprete white space as parameter separation.

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