Difference between revisions of "User:Huybee3/Snippets"

From Wazeopedia
m (Cities Only for a Single State)
m (Tools Required)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
__FORCETOC__
 
==KML generation for Cities Overlay script==
 
==KML generation for Cities Overlay script==
  
 
Instructions to generate KMLs for the Cities Overlay script using data from the 2019 Census ACS.
 
Instructions to generate KMLs for the Cities Overlay script using data from the 2019 Census ACS.
  
===Tools Required===
+
===Tools Utilized===
  
 
* '''[https://gdal.org/ ogr2ogr]''': Converts between file formats for geometric data (Homebrew)
 
* '''[https://gdal.org/ ogr2ogr]''': Converts between file formats for geometric data (Homebrew)
Line 9: Line 10:
 
* '''[https://www.gnu.org/software/sed/ GNU sed]''': Much better than the version of sed provided by default on MacOS (Homebrew)
 
* '''[https://www.gnu.org/software/sed/ GNU sed]''': Much better than the version of sed provided by default on MacOS (Homebrew)
  
===Cities and CDPs from Multiple States===
+
===Cities and CDPs for Multiple States===
  
 
The following set of commands will generate KMLs with Incorporated Places and CDPs for the entire PLN region.
 
The following set of commands will generate KMLs with Incorporated Places and CDPs for the entire PLN region.

Latest revision as of 04:00, 11 October 2019

KML generation for Cities Overlay script

Instructions to generate KMLs for the Cities Overlay script using data from the 2019 Census ACS.

Tools Utilized

  • ogr2ogr: Converts between file formats for geometric data (Homebrew)
  • Mapshaper: Simplify geometric data (npm)
  • GNU sed: Much better than the version of sed provided by default on MacOS (Homebrew)

Cities and CDPs for Multiple States

The following set of commands will generate KMLs with Incorporated Places and CDPs for the entire PLN region.

wFIPs="19 20 27 29 31 38 46"
wStates="IA KS MN MO NE ND SD"
wLayers="28 30"

curl -o "TIGER_#1.json" "https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/tigerWMS_ACS2019/MapServer/{${wLayers// /,}}/query?" \
--data "where=STATE IN (${wFIPs// /%2C})" \
--data "outFields=STATE,BASENAME" \
--data "Geometry=true" \
--data "f=geojson"

eval mapshaper -i TIGER_{${wLayers// /,}}.json combine-files -merge-layers -simplify 40% -o - format=topojson quantization=1e6 -clean | mapshaper -i - name='' -simplify dp 80% -split STATE -o format=geojson precision=0.00001

wIndex=0; for wFIP in $(echo $wFIPs); do

let "wIndex++"; wState="$(cut -d ' ' -f $wIndex <<<"$wStates")"

ogr2ogr -f 'KML' "/vsistdout/" ${wFIP}.json -dsco NameField='BASENAME' |

grep -vE "^\s*<(Style>|ExtendedData>|Document |Folder>|Simple(Data|Field) |\/?Schema(Data)?)" |

gsed -E 's:(<kml .*):\1\n\t<Document>\n\t<Name>\'${State}'_Cities<\/Name>\n\t<visibility>1<\/visibility>\n<Folder id="\'${State}'_Cities"><Name>\'${State}'_Cities<\/Name>:' > ${wState}_Cities.kml

done

Cities Only for a Single State

The following set of commands will generate a KML with Incorporated Places only for the state of MO.

wFIP=29; wState="MO"; wLayer=28

curl "https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/tigerWMS_ACS2019/MapServer/${wLayer}/query?" \
--data "where=STATE IN (${wFIP})" \
--data "outFields=BASENAME" \
--data "Geometry=true" \
--data "f=geojson" |

mapshaper -i - -simplify 40% -o - format=topojson quantization=5e5 -clean | \
mapshaper -i - -simplify dp 80% name='' -o - format=geojson precision=0.00001 |

ogr2ogr -f 'KML' /vsistdout/ /vsistdin/ -dsco NameField='BASENAME' |

grep -vE "^\s*<(Style>|ExtendedData>|Document |Folder>|Simple(Data|Field) |\/?Schema(Data)?)" |

gsed -E 's:(<kml .*):\1\n\t<Document>\n\t<Name>\'${State}'_Cities<\/Name>\n\t<visibility>1<\/visibility>\n<Folder id="\'${State}'_Cities"><Name>\'${State}'_Cities<\/Name>:' > ${wState}_Cities.kml