Changeset 25050


Ignore:
Timestamp:
06/17/20 20:41:20 (5 years ago)
Author:
jdquinn
Message:

CHG: Now trimming newline from grep in piped system call; handling for GDAL version 1

Location:
issm/trunk-jpl/src/m/coordsystems
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/coordsystems/epsg2proj.m

    r25035 r25050  
    1010%      return proj4string='+proj=longlat +datum=wgs84 +no_defs'
    1111%
    12 
    13         [s,r]=system(['gdalsrsinfo epsg:' num2str(epsg) ' | grep PROJ.4 | sed "s/PROJ.4 : //"']);
     12        % First, get GDAL version
     13        [s,r]=system(["gdalsrsinfo --version | awk '{print $2}' | cut -d '.' -f1"]);
    1414
    1515        if s~=0,
    1616                error(r);
    1717        end
     18
     19        version_major=str2num(r)
     20
     21        [s,r]=system(["gdalsrsinfo epsg:" num2str(epsg) " | grep PROJ.4 | tr -d '\n' | sed 's/PROJ.4 : //'"]);
     22
     23        if s~=0,
     24                error(r);
     25        end
     26
     27        if version_major==1,
     28                r=r(2:end-1);
     29        end
     30
    1831        string=(r);
  • issm/trunk-jpl/src/m/coordsystems/epsg2proj.py

    r25035 r25050  
    1 import shlex
    21import subprocess
     2
    33
    44def epsg2proj(epsg): #{{{
     
    1515
    1616    TODO:
    17         - Implement try/catch for proc.communicate()
    18             - In case of Python 2, except socket.timeout: https://docs.python.org/3/library/socket.html?highlight=socket%20timeout#socket.timeout
    19             - In case of Python 3, except TimeoutExpired: https://docs.python.org/3/library/subprocess.html#subprocess.SubprocessError
     17    - Implement try/catch for proc.communicate()
     18        - In case of Python 2, except socket.timeout: https://docs.python.org/3/library/socket.html?highlight=socket%20timeout#socket.timeout
     19        - In case of Python 3, except TimeoutExpired: https://docs.python.org/3/library/subprocess.html#subprocess.SubprocessError
    2020    '''
    21     args = 'gdalsrsinfo epsg:%s | grep PROJ.4 | sed "s/PROJ.4 : //"' % epsg
    22     proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     21
     22    #First, get GDAL version
     23    args = "gdalsrsinfo --version | awk '{print $2}' | cut -d '.' -f1"
     24    proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    2325    outs, errs = proc.communicate()
    24    
    25     if errs != None:
    26         raise RuntimeError('epsg2proj: call to gdalsrsinfo failed: %s' % errs)
     26    if errs != '':
     27        raise RuntimeError("epsg2proj: call to gdalsrsinfo failed: {}".format(errs))
     28
     29    version_major=int(outs)
     30
     31args = "gdalsrsinfo epsg:{} | grep PROJ.4 | tr -d '\n' | sed 's/PROJ.4 : //'".format(epsg)
     32proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     33outs, errs = proc.communicate()
     34if errs != '':
     35    raise RuntimeError("epsg2proj: call to gdalsrsinfo failed: {}".format(errs))
     36
     37    if version_major == 1:
     38        r = r[1:-1]
    2739
    2840    return outs
Note: See TracChangeset for help on using the changeset viewer.