source: issm/trunk-jpl/src/m/coordsystems/epsg2proj.m@ 25050

Last change on this file since 25050 was 25050, checked in by jdquinn, 5 years ago

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

File size: 649 bytes
RevLine 
[24777]1function string = epsg2proj(epsg)
[25035]2%FUNCTION EPSG2PROJ - uses gdalsrsinfo to provide PROJ.4 compatible string from
3%EPSG code
[24777]4%
5% Usage:
6% proj4string = epsg2proj(4326);
7%
[25035]8% Example:
9% proj4string = epsg2proj(4326);
10% return proj4string='+proj=longlat +datum=wgs84 +no_defs'
[24777]11%
[25050]12 % First, get GDAL version
13 [s,r]=system(["gdalsrsinfo --version | awk '{print $2}' | cut -d '.' -f1"]);
[24777]14
[25050]15 if s~=0,
16 error(r);
17 end
[24777]18
[25050]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
[24777]23 if s~=0,
24 error(r);
25 end
[25050]26
27 if version_major==1,
28 r=r(2:end-1);
29 end
30
[24957]31 string=(r);
Note: See TracBrowser for help on using the repository browser.