Hex Tile Functions

The Data SDK contains a variety of endpoints for the Hex Tile system.

Hex Tiles is Studio's analytic tiling system for geospatial data that combines the ability of tiling systems to handle massive datasets with the power of the H3 hierarchical grid system, enabling a tabular data view with full data integrity at all resolutions.


Generate Hex Tiles

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

# 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"
      }
    ]
)
uf-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
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"
        }
    ]
}'

Learn more in the SDK reference

🧪

Try it now in the interactive API explorer


Enrich Dataset with Hex Tiles

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

# 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",
)
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"
}'

Learn more in the SDK reference.

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.

# 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]
          ]
        ]
      }
    }
)
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.

Learn more in the SDK reference.