Hex Tile Functions

Generate Hex Tiles

Process a geospatial dataset into Hex Tiles using the Studio Data SDK. Pass a source UUID or dataset record to convert to Hex Tiles. Requires either a hex (H3) column or latitude and longitude columns.

Example Code

Python

# Generate Hex Tiles
data_sdk.generate_hextile(
    source="0b341204-1a76-4c1e-82a1-a856f28c522e",
    source_time_column = "time",
    source_lat_column = "lat",
    source_lng_column = "lon",
    finest_resolution = 9,
    time_intervals= ["HOUR"],
    output_columns= [\
      {\
        "source_column": "precip_kg/m2",\
        "target_column": "precip_sum",\
        "agg_method": "sum"\
      }\
    ]
)

CLI

fsq-data-sdk generate-hextile
  --source e32f527e-0917-40aa-955f-8d55105f9673
  --source-lat-column Latitude
  --source-lng-column Longitude
  --output-column '{"sourceColumn":"Magnitude", "targetColumn":"Avg Magnitude", "aggMethod":"mean"}'
  --output-column '{"sourceColumn":"Depth", "targetColumn":"Max Depth", "aggMethod":"max"}'
  --finest-resolution 5

HTTP

curl -X POST https://data-api.foursquare.com/internal/v1/datasets/hextile \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
--data-raw '{\
    "source": "<source_dataset_id>",\
    "sourceHexColumn": "hex",\
    "sourceTimeColumn": "datestr",\
    "timeIntervals": ["DAY"],\
    "targetResOffset": 4,\
    "outputColumns": [\
        {\
        "sourceColumn": "metric",\
        "targetColumn": "metric_sum",\
        "aggMethod": "sum"\
        }\
    ]\
}'

Enrich Dataset with Hex Tiles

You can enrich a dataset with Hex Tiles. Enriching refers to the process of joining Hex Tiles with another dataset to enrich them with contextual information. Requires a dataset to enrich with, which can be a UUID, dataset object, or dataframe.

Example Code

Python

# Enrich dataset with Hex Tiles
data_sdk.enrich(
    dataset="my-dataset-uuid",
    source_id="my-hex-tile-uuid",
    source_column="some_value",
    lat_column="lat",
    lng_column="lng",
    time_column="date",
)

HTTP

curl -X POST https://data-api.foursquare.com/internal/v1/datasets/hextile \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-H 'Accept: text/csv' \
--data-raw '{\
    "type": "enrich",\
    "input": [\
        {\
            "type": "dataset",\
            "uuid": "my-target-uuid"\
        }\
    ],\
    "sourceId": "my-hex-tile-uuid",\
    "sourceColumn": "some_value",\
    "timeColumn": "date",\
    "targetType": "LATLNG",\
    "latColumn": "lat",\
    "lngColumn": "lng"\
}'

Extract Hex Tiles

You may specify an area of Hex Tiles (represented by a GeoJSON geometry) for extraction. This function returns a geopandas H3 dataframe containing all fields from the Hex Tile dataset at the specified resolution.

Example Code

Python

# Extract Hex Tiles within a specified GeoJSON geometry
extracted_dataset = data_sdk.tile_extract(
    source_id="3cf521ed-534f-4670-bd50-7e06582d38be",
    geojson=
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [\
          [\
            [0, 0],\
            [0, 10],\
            [10, 0],\
            [0, 0]\
          ]\
        ]
      }
    }
)

HTTP

curl -X POST https://data-api.foursquare.com/internal/v1/query HTTP/1.1
    Note: Extracting Hextiles makes use of Studio's Query API.
    Please contact us if you wish to use the Query API to extract Hex Tiles.