Opened 11 years ago

Closed 8 years ago

#2140 closed defect (fixed)

m.proj does not handle cs2cs failure

Reported by: wenzeslaus Owned by: grass-dev@…
Priority: normal Milestone: 7.0.5
Component: Projections/Datums Version: svn-trunk
Keywords: m.proj, cs2cs Cc:
CPU: All Platform: All

Description

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?

Change History (10)

comment:1 by wenzeslaus, 11 years ago

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:"

comment:2 by jrobparsons, 9 years ago

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.

comment:3 by neteler, 9 years ago

(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.

comment:4 by jrobparsons, 9 years ago

Studying the pyproj wrapper now.

comment:5 by jrobparsons, 9 years ago

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:\>

in reply to:  5 comment:6 by neteler, 9 years ago

Replying to 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.

comment:7 by jrobparsons, 9 years ago

Sent patch to Vaclav Petras.

  1. PEP8 compliant except for 2 GUI parser 'description' lines.

rp@concepts:~/grass7_trunk/scripts/m.proj$ pep8 m.proj.py m.proj.py:28:80: E501 line too long (85 > 79 characters) m.proj.py:78:80: E501 line too long (97 > 79 characters)

  1. Replaced tabs with spaces.

indents are on 4 space boundaries.

  1. Added test for the presence of '+' in proj_in and proj_out strings.

if proj_in:

if '+' in proj_in:

in_proj = proj_in

else:

grass.fatal(_("Invalid PROJ.4 input specification"))

  1. Removed this comment inserted by previous programmer.

# FIXME: input_x,y needs to split on multiple whitespace between them

This appears to not be a problem.

comment:8 by wenzeslaus, 9 years ago

With some minor modifications patch applied in r68094 and r68095. I wonder if this is enough to close the ticket. It solves the original issue but it does not handle cs2cs failures in general.

comment:9 by martinl, 9 years ago

Milestone: 7.0.07.0.5

comment:10 by martinl, 8 years ago

Resolution: fixed
Status: newclosed

Closing, feel free to reopen if needed.

Note: See TracTickets for help on using tickets.