Skip to content

Commit

Permalink
added powershell script to download data per
Browse files Browse the repository at this point in the history
country and convert to geojsonl extension
  • Loading branch information
andwoi committed Mar 24, 2023
1 parent 4ac48c9 commit 310a7a5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions scripts/make-gis-friendly.ps1
@@ -0,0 +1,41 @@

$CountryToProcess = "Abyei"

$DatasetLinksUrl = "https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv"
$CompressedData = "compressed"
$ExpandedData = "expanded"

mkdir $CompressedData -Force
mkdir $ExpandedData -Force

Function Expand-GZip{
Param(
$infile,
$outfile
)
$inputData = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
$output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
$gzipStream = New-Object System.IO.Compression.GzipStream $inputData, ([IO.Compression.CompressionMode]::Decompress)
$buffer = New-Object byte[](1024)
while($true){
$read = $gzipstream.Read($buffer, 0, 1024)
if ($read -le 0){break}
$output.Write($buffer, 0, $read)
}
$gzipStream.Close()
$output.Close()
$inputData.Close()
}

$resp = Invoke-WebRequest -Uri $DatasetLinksUrl
$links = ($resp.ToString() | ConvertFrom-Csv)

foreach ($link in $links) {
if ($link.Location -eq $CountryToProcess) {
Write-Host "Country: $($link.Location) QuadKey: $($link.QuadKey) Url: $($link.Url)"
$downloadedGzip = "$CompressedData\$($link.Location)-$($link.QuadKey).csv.gz"
$decompressedData = "$ExpandedData\$($link.Location)-$($link.QuadKey).geojsonl"
Invoke-WebRequest -Uri $link.Url -OutFile $downloadedGzip
Expand-GZip $downloadedGzip $decompressedData
}
}

0 comments on commit 310a7a5

Please sign in to comment.