HTTP Requests
Call a UDF via HTTP requests and pass geometries as query parameters or as XYZ tiles.
Specify geometry
There are 2 ways to specify geometries. The first method involves specifying XYZ tiles as path parameters and the second method entails passing a geometry query parameter.
With an XYZ Tile
!curl -L -XGET "https://www.fused.io/server/v1/realtime-shared/55ffe996fc2bd635cde3beda7e2632005e228798a1ef333297240b86af7d12a4/run/tiles/16/11242/26162?dtype_out_vector=csv"
With parameters for latitude and longitude pairs
This sample URL passes a geometry's polygon pairs in the lng_list
and lat_list
parameters. It also passes parameters for census_variable
, costing
, duration
,
count
, and buffer
.
!curl -L -XGET "https://app-staging.fused.io/server/v1/realtime-shared/efff19cb8e3e12d0df1f307c0198384c746b961635d404eb1302cf15ad031485/run/file?dtype_out_vector=csv&census_variable=median household income&lng_list=-74.01, -74.010901, -74.000008, -73.98255, -73.9830327, -73.99468, -73.9905&lat_list=40.71021, 40.714353, 40.728349, 40.731949, 40.7150147, 40.7252, 40.730013&costing=auto&duration=20&count=TRUE&buffer=5"
With a GeoJSON
When parameters are passed to a User Defined Function (UDF) via HTTP requests, they must be encodable. This is because HTTP is a text-based protocol, and any data transmitted over it, including parameters, must be represented in a format that is compatible with the protocol.
The best way to pass a geometry as a query parameter is to use a URL-encoded GeoJSON. It's possible to encode a GeoJSON with jq
.
# !apt-get install jq -q
!\
export GEOJSON_ENCODED=$(printf '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"x": 11243, "y": 26163, "z": 16}, "geometry": {"type": "Polygon", "coordinates": [[[-118.23486328125, 34.075412438417395], [-118.23486328125, 34.070862323766306], [-118.2403564453125, 34.070862323766306], [-118.2403564453125, 34.075412438417395], [-118.23486328125, 34.075412438417395]]]}}]}' | jq --slurp --raw-input --raw-output @uri) && \
echo $GEOJSON_ENCODED && \
curl -L -XGET "https://www.fused.io/server/v1/realtime-shared/55ffe996fc2bd635cde3beda7e2632005e228798a1ef333297240b86af7d12a4/run/file?dtype_out_vector=geojson&bbox=${GEOJSON_ENCODED}"