How can I upload a Shapefile to the vector service?

Translate ESRI Shapefiles with the ogr2ogr tool on Workbench to upload data to the DL Vector service.

The Vectors service exists to store and retrieve collections of WGS84 GeoJSON feature data. To upload data stored in formats other than GeoJSON and coordinate reference systems other than WGS84, use the ogr2ogr command line utility, which is installed by default on the Workbench IDE. 

To begin, upload your shapefile (.shp) and its sidecar files (.dbf, .shx, and .prj) to a location in Workbench using the file upload tool in the file manager to the left of the screen.Screen Shot 2020-06-30 at 12.04.07 AM

Once the file has uploaded, you may unzip using the pre-installed unzip utility. Within a notebook using the "!" prefixed to run a command-line utility enter the following:


Now, use ogr2ogr to convert to the DL Vector compatible format, newline-delimited GeoJSON.

!ogr2ogr -f GeoJSONSeq my_shapefile.geojsonl my_shapefile.shp

The file can now be uploaded to the DL Vector service, create a FeatureCollection to contain the data

from descarteslabs.vectors import FeatureCollection

fc = FeatureCollection.create(product_id='my_feature_collection',
title='The Title of My Feature Collection',
description='A description of My Feature Collection.')

Then load the data from the .geojsonl file created with ogr2ogr

upload_task = fc.upload('myshapefile.geojsonl')

The upload can be monitored via the upload_task object returned. 


Features with invalid geometry may fail to upload correctly. To work around this, you may set the max_errors parameter to some value between zero and the length of the collection. This will allow  valid features to load, with up to max_errors tolerated before cancelling the upload. Invalid features that failed to load will be logged in the "errors" attribute of the result. Common reasons for invalid features involve geometries that do not honor the "right hand rule", twisted geometries, and geometries with overlapping or duplicate vertices. The system will attempt to repair these, but will retain a copy of the original geometry by default. Adjust the fix_geometry upload parameter to control the repair function.