Loading the data into the dataset

To load the data into the new dataset, we will iterate through the features contained in the zip codes GeoJSON, writing them all to the dataset (instead of just one as demonstrated earlier). As this file is larger than 5MB, it must be loaded using the API, which is accessed using the mapbox module. The ID of the dataset (retrieved using the datasets.list method), the row ID, and the feature, are all required parameters for the update_feature method:

listing_resp = datasets.list()dataset_id = [ds['id'] for ds in listing_resp.json()][0]data = json.load(open(r'ztca_bayarea.geojson'))for count,feature in enumerate(data['features']):    resp = datasets.update_feature(dataset_id, count, feature)

The completed dataset ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.