This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
teaching:m_r:excersize:proj4 [2012/11/07 16:20] karina [Awk] |
teaching:m_r:excersize:proj4 [2021/08/14 04:21] (current) |
||
---|---|---|---|
Line 3: | Line 3: | ||
- | ===== Proj4 ===== | + | ===== Proj.4 |
Reference: [[https:// | Reference: [[https:// | ||
+ | |||
+ | |||
+ | PROJ.4 is a library for performing conversions between cartographic projections. The library is based on the work of Gerald Evenden at the USGS,[2] but is now an OSGeo project maintained by Frank Warmerdam. The library also ships with executables for performing these transformations from the command line. (Reference: [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | == Download program == | ||
+ | ^Windows^Mac^Linux^ | ||
+ | |[[http:// | ||
+ | |||
+ | |||
===== Awk ===== | ===== Awk ===== | ||
+ | Awk is a terminal program / script program. | ||
+ | |||
Reference: [[http:// | Reference: [[http:// | ||
Line 17: | Line 30: | ||
== Download program == | == Download program == | ||
^Windows^Mac^Linux^ | ^Windows^Mac^Linux^ | ||
- | | |[[http:// | + | |[[http:// |
+ | |||
+ | ===== Awk/proj4 script ===== | ||
+ | Script that convert gga-strings to UTM co-ordinates. | ||
+ | |||
+ | |||
+ | <file bash ggacs2cs.awk> | ||
+ | # | ||
+ | function usage(){ | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "NFN=3 (input field latitude)" | ||
+ | print "EFN=5 (input field longitude)" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | |||
+ | } | ||
+ | #Windows command: gawk -f ggacs2cs.awk -v ECHO=true PRINT2FILE=true OUTPUTFILE=utm_row4_adana EPSGTO=32636 ggaLog.log | ||
+ | #Windows command: gawk -f ggacs2cs.awk -v PRINT2FILE=true OUTPUTFILE=gga_l_u EPSGTO=32636 GGAlinksoben.log | ||
+ | # | ||
+ | |||
+ | # TODO: feed all coordinates to cs2cs in one large chunk, not line per line | ||
+ | # TODO: use optarg: http:// | ||
+ | BEGIN{ | ||
+ | <<<<<<< | ||
+ | CONVFMT=" | ||
+ | ======= | ||
+ | CONVFMT=" | ||
+ | >>>>>>> | ||
+ | # while ((c = getopt(ARGC, | ||
+ | # if (c == " | ||
+ | # | ||
+ | # }# else if (c == " | ||
+ | #} | ||
+ | |||
+ | if(MYFS=="" | ||
+ | FS="," | ||
+ | } | ||
+ | OFS=FS | ||
+ | if (EPSGTO=="" | ||
+ | EPSGTO=" | ||
+ | } | ||
+ | if (EPSGFROM=="" | ||
+ | EPSGFROM=" | ||
+ | } | ||
+ | if (CNV=="" | ||
+ | CNV=" | ||
+ | } | ||
+ | if(NFN=="" | ||
+ | if(EFN=="" | ||
+ | if(HFN=="" | ||
+ | if(ECHO=="" | ||
+ | if(PRINT2FILE=="" | ||
+ | if(OUTPUTFILE=="" | ||
+ | } | ||
+ | |||
+ | function nmea2dd(nmeacoord){ | ||
+ | dn=int(nmeacoord/ | ||
+ | return dn+((nmeacoord-(dn*100.0))/ | ||
+ | } | ||
+ | function cs2cs(coordarray){ | ||
+ | CMD=" | ||
+ | # | ||
+ | gkarray[0]="" | ||
+ | CMD | getline TRANSFCOORD | ||
+ | # | ||
+ | split(TRANSFCOORD, | ||
+ | split(gkarray[2], | ||
+ | # print C[0] | ||
+ | # GKR=C[1] | ||
+ | # GKH=D[1] | ||
+ | coordarray[7]=gkarray[1] | ||
+ | coordarray[6] = D[1] #northing | ||
+ | coordarray[8] = D[2] #easting | ||
+ | # print " | ||
+ | # | ||
+ | } | ||
+ | |||
+ | # function wgs84toepsg(coord_n_e_h_to){ | ||
+ | # | ||
+ | # # print CMD | ||
+ | # | ||
+ | # CMD | getline TRANSFCOORD | ||
+ | # # | ||
+ | # | ||
+ | # | ||
+ | # # print C[0] | ||
+ | # # GKR=C[1] | ||
+ | # # GKH=D[1] | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # print " | ||
+ | # | ||
+ | # } | ||
+ | {if (ECHO!=" | ||
+ | #if (true){ | ||
+ | # for (i=1; | ||
+ | # print i" | ||
+ | # } | ||
+ | #} | ||
+ | } | ||
+ | /GGA/{ | ||
+ | # | ||
+ | transarray[0]="" | ||
+ | transarray[1]=nmea2dd($NFN) # ddlat | ||
+ | transarray[2]=nmea2dd($EFN) # ddlon | ||
+ | transarray[3]=$HFN # | ||
+ | transarray[4]=EPSGFROM | ||
+ | transarray[5]=EPSGTO | ||
+ | # | ||
+ | cs2cs(transarray) | ||
+ | if(CNV!=" | ||
+ | $1=" | ||
+ | $NFN=transarray[6] | ||
+ | $EFN=transarray[7] | ||
+ | $HFN=transarray[8] | ||
+ | print $0 | ||
+ | }else | ||
+ | print transarray[6] FS transarray[7] FS transarray[8] | ||
+ | #write to file: works in windows | ||
+ | if(PRINT2FILE==" | ||
+ | #{print transarray[6] FS transarray[7] FS transarray[8] > OUTPUTFILE" | ||
+ | # | ||
+ | {print transarray[1] FS transarray[2] FS transarray[3] > OUTPUTFILE" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | </ |