Skip to content

Instantly share code, notes, and snippets.

@maskati
Last active September 7, 2023 12:47
Show Gist options
  • Save maskati/b454a7c9478fc153dfe62ac7547d5d0a to your computer and use it in GitHub Desktop.
Save maskati/b454a7c9478fc153dfe62ac7547d5d0a to your computer and use it in GitHub Desktop.

This script retrieves published Azure location information and transforms it into GeoJSON format, with Point features indicating Azure regions and LineString features indicating links between paired regions.

$locations=az account list-locations --query "[?metadata.regionType=='Physical']"|convertfrom-json
@{type='FeatureCollection';features=$($locations|?{$_.metadata.pairedRegion.count -eq 1}|%{$r=$_;$p=$locations|?{$_.name -eq $r.metadata.pairedRegion[0].name}|select -first 1;if($null -ne $p -and -not (($r.metadata.longitude -eq 0 -and $r.metadata.latitude -eq 0) -or ($p.metadata.longitude -eq 0 -and $p.metadata.latitude -eq 0))){@{type='Feature';properties=@{region=$r.name;paired=$p.name};geometry=@{type='LineString';coordinates=@(@([double]$r.metadata.longitude,[double]$r.metadata.latitude),@([double]$p.metadata.longitude,[double]$p.metadata.latitude))}}}})+$($locations|?{-not ($_.metadata.longitude -eq 0 -and $_.metadata.latitude -eq 0)}|%{@{type='Feature';properties=@{name=$_.name;displayName=$_.displayName;physicalLocation=$_.metadata.physicalLocation;regionType=$_.metadata.regionType;regionCategory=$_.metadata.regionCategory;pairedRegions=($_.metadata.pairedRegion.name -join ',');'marker-symbol'='communications-tower'};geometry=@{coordinates=@([double]$_.metadata.longitude,[double]$_.metadata.latitude);type='Point'}}})}|convertto-json -depth 5 > azure-locations-map.geojson

An example output is included in azure-locations-map.geojson.

GitHub supports displaying GeoJSON files, but the map rendering is somewhat unstable (sometimes shows only blue, sometimes fixed by force refreshing the page). A better rendering of the same azure-locations-map.geojson can be viewed at geojson.io.

image

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment