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

Support for MultiPolygon #56

Closed
zacdezgeo opened this issue Sep 17, 2024 · 1 comment
Closed

Support for MultiPolygon #56

zacdezgeo opened this issue Sep 17, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@zacdezgeo
Copy link
Collaborator

@andresfchamorro @bpstewar; can you provide the exact requests used to reproduce the bug and provide a little more description?

@zacdezgeo zacdezgeo added the bug Something isn't working label Sep 17, 2024
@andresfchamorro andresfchamorro changed the title Summary errors with multiple part or small polygons Support for MultiPolygon Sep 17, 2024
@andresfchamorro
Copy link
Collaborator

Thanks for opening the issue, I will open a new one for small polygons as it's different and probably minor.

Do you think the API could support multi polygons? There are likely going to be many admin areas like this one with coastal features.

The response is 422 but the text for the exception doesn't yield anything. The json does say Input should be 'Polygon

from typing import Dict
import requests
import geopandas as gpd
import pandas as pd
from geojson_pydantic import Feature, Polygon

BASE_URL = "https://space2stats.ds.io"
FIELDS_ENDPOINT = f"{BASE_URL}/fields"
SUMMARY_ENDPOINT = f"{BASE_URL}/summary"

iso3 = 'KEN'
adm = 'ADM1'
url = f'https://www.geoboundaries.org/api/current/gbOpen/{iso3}/{adm}/'
res = requests.get(url).json()
adm = gpd.read_file(res['gjDownloadURL'])
aoi = adm.loc[42]

feature = {
    "type": "Feature",
    "geometry": aoi.geometry.__geo_interface__,
    "properties": { key: value for key, value in aoi.items() if key != 'geometry' }
}

AOIModel = Feature[Polygon, Dict]

# Define the Request Payload
request_payload = {
    "aoi": feature,
    "spatial_join_method": "centroid",
    "fields": ["sum_pop_2020"], 
    "geometry": "polygon"
}

# Get Summary Data
response = requests.post(SUMMARY_ENDPOINT, json=request_payload)
if response.status_code != 200:
    raise Exception(f"Failed to get summary: {response.text}")

summary_data = response.json()
df = pd.DataFrame(summary_data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants