Changeset 25050
- Timestamp:
- 06/17/20 20:41:20 (5 years ago)
- Location:
- issm/trunk-jpl/src/m/coordsystems
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/coordsystems/epsg2proj.m
r25035 r25050 10 10 % return proj4string='+proj=longlat +datum=wgs84 +no_defs' 11 11 % 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"]); 14 14 15 15 if s~=0, 16 16 error(r); 17 17 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 18 31 string=(r); -
issm/trunk-jpl/src/m/coordsystems/epsg2proj.py
r25035 r25050 1 import shlex2 1 import subprocess 2 3 3 4 4 def epsg2proj(epsg): #{{{ … … 15 15 16 16 TODO: 17 18 19 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 20 20 ''' 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) 23 25 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 31 args = "gdalsrsinfo epsg:{} | grep PROJ.4 | tr -d '\n' | sed 's/PROJ.4 : //'".format(epsg) 32 proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 33 outs, errs = proc.communicate() 34 if errs != '': 35 raise RuntimeError("epsg2proj: call to gdalsrsinfo failed: {}".format(errs)) 36 37 if version_major == 1: 38 r = r[1:-1] 27 39 28 40 return outs
Note:
See TracChangeset
for help on using the changeset viewer.