Last active
October 18, 2017 20:41
-
-
Save maphew/8d97e7b68ce3df6f281e7bf3100a964e to your computer and use it in GitHub Desktop.
Convert Arcinfo Ascii Grid file to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# asc2json | |
# Convert Arcinfo Ascii Grid file to JSON | |
# RegEx replace: | |
# - strip leading whitespace | |
# - strip line not beginning with a number | |
# - add opening `[` to beginning of line | |
# - space to comma | |
# - end of line to `],` | |
# - strip empty list `[],` | |
$infile = $args[0] | |
$outfile = (Get-Item $infile).Basename + '.json' | |
(Get-Content $infile) | | |
Foreach-Object {$_ -replace "^\s*", ""} | | |
Foreach-Object {$_ -replace "^\D.*", ""} | | |
Foreach-Object {$_ -replace "^", "["} | | |
Foreach-Object {$_ -replace "\ ", ","} | | |
Foreach-Object {$_ -replace "$", "],"} | | |
Foreach-Object {$_ -replace "^\[\],$", ""} | | |
Set-Content $outfile | |
# Remove empty lines | |
(Get-Content $outfile) | | |
? {$_.trim() -ne "" } | | |
Set-Content $outfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sparked by RaumZeit/MarchingSquares.js#9