Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The database is no longer showing .zip files #34

Open
ireneeeeeeeeeee opened this issue Oct 17, 2022 · 4 comments
Open

The database is no longer showing .zip files #34

ireneeeeeeeeeee opened this issue Oct 17, 2022 · 4 comments

Comments

@ireneeeeeeeeeee
Copy link

Hi,

I'm trying to download building footprints for Greece. There seems to no longer be .zip files and instead csv.gz files, is there a link to access GeoJSON files for Greece specifically?

When I import the JSON database into ArcGIS it only recognizes the region tiles and not the building footprint info.

Please help, thank you!

@Estharx
Copy link

Estharx commented Oct 20, 2022

Did anyone managed to work with the csv file with QGIS like we used to when it was directly GeoJSON ?

@andwoi
Copy link
Contributor

andwoi commented Oct 25, 2022

The file contents are line delimited GeoJSON. On Windows you can do the following to extract and rename and ArGIS/QGIS will recognize:

Invoke-WebRequest url.to.csv.gz -outfile local.path.to.csv.gz
7z e local.path.to.csv.gz
Move-Item local.path.to.csv local.path.to.geojsonl

image

If you want to get all of Greece, you use a script like this and it might save some time:

import pandas as pd
import geopandas as gpd
from shapely.geometry import shape
dataset_links = pd.read_csv("https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv")
greece_links = dataset_links[dataset_links.Location == 'Greece']
for _, row in greece_links.iterrows():
    df = pd.read_json(row.Url, lines=True)
    df['geometry'] = df['geometry'].apply(shape)
    gdf = gpd.GeoDataFrame(df, crs=4326)
    gdf.to_file(f"{row.QuadKey}.geojson", driver="GeoJSON")

Edit: updated link for new location

@dotysan
Copy link

dotysan commented Nov 23, 2022

Those csv aren't csv, but instead json.

Here's a code snippet to extract and properly rename.

# url is looked up from dataset-links.csv
path = url.split('/')
gzfile = path[-1]
jsonfile = f'{gzfile[:-6]}json'
with gzip.open(gzfile, 'rb') as gz:
    with open(jsonfile, 'wb') as js:
        shutil.copyfileobj(gz, js)
os.remove(gzfile)

@Dimitris-geo
Copy link

Dimitris-geo commented Jul 29, 2024

Great code @andwoi , just add one more line to get directly shape files (.shp) just to save some time.

import pandas as pd
import geopandas as gpd
from shapely.geometry import shape

def main():
# this is the name of the geography you want to retrieve. update to meet your needs
location = 'Greece'

dataset_links = pd.read_csv("https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv")
greece_links = dataset_links[dataset_links.Location == location]
for _, row in greece_links.iterrows():
    df = pd.read_json(row.Url, lines=True)
    df['geometry'] = df['geometry'].apply(shape)
    gdf = gpd.GeoDataFrame(df, crs=4326)
    gdf.to_file(f"{row.QuadKey}.geojson", driver="GeoJSON")
    gdf.to_file(f"{row.QuadKey}.shp")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants