import requests
import json
import pandas as pd

resp = requests.get(
	"https://webapps.portofantwerp.com/arcgis/rest/services/extern/detailkaart_fs/FeatureServer/60/query?where=LPL!='kip'&returnGeometry=true&outSR=4326&f=json&outFields=LPL,FILIAAL"
)

resp_d = json.loads(resp.text)

berths = {
	"lpl_id": [],
	"filiaal": [],
	"polygon": [],
	"center_lon": [],
	"center_lat": [],
}

for x in resp_d["features"]:
	berths["lpl_id"].append(x["attributes"]["LPL"])
	berths["filiaal"].append(x["attributes"]["FILIAAL"])
	ring = x["geometry"]["rings"][0]
	berths["polygon"].append(ring)
	berths["center_lon"].append(sum([a for a, _ in ring]) / len(ring))
	berths["center_lat"].append(sum([a for _, a in ring]) / len(ring))

berths_pdf = pd.DataFrame(berths)
print(berths_pdf)

berths_pdf.to_csv("berths.csv")