Bing US Buildings to PostGIS

Bing released 125+ million US building footprints, blog post here and GitHub here. To do something with them..

Grab the files:

wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Alabama.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Alaska.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Arizona.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Arkansas.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/California.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Colorado.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Connecticut.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Delaware.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/DistrictofColumbia.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Florida.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Georgia.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Hawaii.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Idaho.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Illinois.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Indiana.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Iowa.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Kansas.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Kentucky.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Louisiana.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Maine.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Maryland.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Massachusetts.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Michigan.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Minnesota.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Mississippi.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Missouri.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Montana.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Nebraska.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Nevada.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NewHampshire.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NewJersey.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NewMexico.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NewYork.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NorthCarolina.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/NorthDakota.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Ohio.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Oklahoma.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Oregon.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Pennsylvania.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/RhodeIsland.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/SouthCarolina.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/SouthDakota.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Tennessee.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Texas.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Utah.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Vermont.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Virginia.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Washington.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/WestVirginia.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Wisconsin.zip
wget https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Wyoming.zip

Then

unzip \*.zip

California and Texas are too big for GDAL so here’s a semi-broken script to split them up:

#!/usr/bin/ruby

f = File.open("Texas.geojson", "r")

f1 = File.open("TX-1.geojson", "w")
f2 = File.open("TX-2.geojson", "w")

count = 0
toggle = true

f.each_line do |line|
        if count < 4
                f1.write(line)
                f2.write(line)
        else
                if line == "  ]" #FIXME this doesn't match, probably needs line.chomp
                        f1.write("]}")
                        f2.write("]}")
                        exit
                end
                if toggle
                        f1.write(line)
                else
                        f2.write(line)
                end
                toggle = !toggle
        end
        count = count + 1
end

Then assuming GDAL is installed and you have a PostGIS db:

for f in *.geojson; do ogr2ogr -f "PostgreSQL" PG:"dbname=steve user=steve" $f -nln usa_buildings -append; done

 

Comments are closed.

Powered by WordPress. Designed by WooThemes