#!/usr/bin/awk -f # postprocess GeoJSON representation of EPDI's Global UTM zones grid # as ESRI shapefile: # http://www.enviroprojects.org/geospatial-services/gis-resources/global-utm-zones/view # to add EPSG SRIDs for WGS84 (and make CATID an integer field for PK_UID use) # !!! DANGER DANGER DANGER - YES, I AM NAÏVELY MESSING ABOUT WITH JSON HERE !!! # scruss - 2013-08-08 - WTFPL (srsly) BEGIN { code=""; lat=""; epsg_wgs84_hemisphere=""; } ($10 ~ /LAT/) { # which hemisphere are we in? lat=$11; sub(/,/, "", lat); lat = lat + 0.0; # ensure numeric if (lat > 0.0) { # northern hemisphere epsg_wgs84_hemisphere=6; } else { # southern hemisphere epsg_wgs84_hemisphere=7; } } ($12 ~ /CODE/) { code=$13; gsub(/\"/, "", code); # strip off alpha grid sub(/[C-X],/, "", code); # strip off alpha grid code = sprintf("%02d", code + 0); # ensure padded numeric } ($6 ~ /CATID/) { # make CATID field an integer sub(/\.0/, "", $7); } { if (($6 ~ /CATID/) && (code !~ /^$/) && (epsg_wgs84_hemisphere !~ /^$/)) { # be appropriately paranoid that everything's initialized before adding fields $12 = "\"EPSGSRID\": 32" epsg_wgs84_hemisphere code ", " $12; } print $0; # this is a filter; copy everything }