import requests
from requests.auth import HTTPBasicAuth
from urllib.parse import urlencode
from io import BytesIO
import geopandas
# set host, like http://localhost:8000, to where your Data Hub is running
HOST = ""
# in case of basic auth set to HTTPBasicAuth('user', 'password')
AUTH = None
# API TOKEN
TOKEN = ""
q = {
"shape_type": "",
# Simplify geometry to reduce complexity/size in unit of Shapes,
# for WGS84 degree: 0.001 ~> 111.3m
# https://shapely.readthedocs.io/en/latest/manual.html#object.simplify
# "simplify": 0.01
}
response = requests.get(
f"{HOST}/api/shapes/geometry/?{urlencode(q)}",
headers={"Authorization": f"Bearer {TOKEN}"},
auth=AUTH,
)
if response.status_code == 200:
_gdf = geopandas.read_file(BytesIO(response.content))
d = response.json()
else:
raise Exception(f"Request failed ({response.status_code}): {response.text}")
There is no ready use snippet for API usage in R yet, though you can adapt the Python example to your R needs.