microsoft / microsoft/GlobalMLBuildingFootprints

STAC API fails for some countries (e.g., Belgium)

Open
#40 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
277
PR merge metrics
No merged PRs in 30d

Description

I am trying to DL a representative Lat/Long for each footprint. Using the STAC API in the code chunk 1 below fails to get data for several countries (basically, the parameter "items" does not read the full info it needs normally). So, I tried the code chunk 2 to get what I wanted (but it's so slow to do so). Any reason why those info missing for some countries?

Code chunk 1

import os
import geopandas
import planetary_computer
import pystac_client
import pandas as pd

location = 'Belgium'

catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)

#os.chdir("xxxx")
for i in location:
    if not os.path.isfile(i + '_MS_Bldgs.csv'):
        try:
            print(i)
            items = catalog.search(
            collections=["ms-buildings"], query={"msbuildings:region": {"eq": i}}
            )
            item = next(items.items())
            asset = item.assets["data"]

            df = geopandas.read_parquet(
                asset.href, storage_options=asset.extra_fields["table:storage_options"]
            )
            s = df.representative_point()
            #s.head()
            ss = pd.DataFrame(data = {'long': s.x, 'lat': s.y})
            #ss.head()
            ss.to_csv(i + '_MS_Bldgs.csv')
        except:
            print("#################################")
            print("Failed to run for: " + i)
            print("#################################")

Code chunk 2

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

location = 'Belgium'

dataset_links = pd.read_csv("https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv")
my_links = dataset_links[dataset_links.Location == location]
out_file_name = location + '.csv'
pd.DataFrame(columns=['long', 'lat']).to_csv(out_file_name, index = False)
for _, row in my_links.iterrows():
    df = pd.read_json(row.Url, lines=True)
    df['geometry'] = df['geometry'].apply(shape)
    df = gpd.GeoDataFrame(df, crs=4326)
    df = df.representative_point()
    df = pd.DataFrame(data = {'long': df.x, 'lat': df.y})
    df.to_csv(out_file_name, mode = 'a', index = False, header = False)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the code chunk 1 loop and the catalog.search call, then compare its results with dataset-links.csv and the code chunk 2 loading path. Confirm why the STAC query does not produce the expected data for Belgium and document a reproducible correction or explanation, with the representative-point CSV output as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.