microsoft / GlobalMLBuildingFootprints

Worldwide building footprints derived from satellite imagery
Other
1.38k stars 202 forks source link

Multiple rows found #76

Open Molinetti opened 11 months ago

Molinetti commented 11 months ago

Hi everybody!

i am running into an issue with a tile. specifically, when i try to run my coordinates, an error occurs that looks like this:

Multiple rows found for QuadKey: 122010203

The coordinates: (Sicily, Italy)

aoi_geom = { "coordinates": [ [ [ 12.433563373156886, 38.04256270793016 ], [ 12.433563373156886, 37.77014720230194 ], [ 12.828942380919273, 37.77014720230194 ], [ 12.828942380919273, 38.04256270793016 ], [ 12.433563373156886, 38.04256270793016 ] ] ], "type": "Polygon", }

is there a way around this? is the problem related to the tile itself? Thanks for your time.

plo97 commented 10 months ago

I have the same problem

Molinetti commented 10 months ago

i solved the issue by dowloading every row. i am not sure of the consequences of it, but it works for me. I made the following substitution to the elif that handles multiple rows:

elif rows.shape[0] > 1:
          # insert custom code
            print(f"Multiple rows found for QuadKey: {quad_key}")
            for i in range(rows.shape[0]):
                url = rows.iloc[i]["Url"]
                df2 = pd.read_json(url, lines=True)
                df2["geometry"] = df2["geometry"].apply(shapely.geometry.shape)

                gdf = gpd.GeoDataFrame(df2, crs=4326)
                fn = os.path.join(tmpdir, f"{quad_key}_{i}.geojson")
                tmp_fns.append(fn)
                if not os.path.exists(fn):
                    gdf.to_file(fn, driver="GeoJSON")