Analyze your data
Buffer, aggregate, find the nearest and intersect your GeoJSON with MapScale analysis endpoints, then draw the result.
Intermediate
What you can run
Four analysis operations take GeoJSON and return GeoJSON. They need a secret key, so call them from your server. Which request fields each operation accepts is listed in the API reference; the examples here show the shape of the call, not the final field names.
POST /v1/analysis/buffer area within a distance of each feature
POST /v1/analysis/aggregate count or summarize features per province, district, subdistrict or hex cell
POST /v1/analysis/nearest the closest features to a point
POST /v1/analysis/intersect which features of one dataset overlap features of anotherRun an analysis
Send the features and the operation's options as a JSON body.
# Buffer every feature of one of your datasets by 1 km (meters: 0.1 to 50000).
curl -X POST "https://api.mapscale.io/v1/analysis/buffer" \
-H "x-api-key: sk_live_YOUR_SECRET_KEY" \
-H "content-type: application/json" \
-d '{ "datasetId": "YOUR_DATASET_ID", "meters": 1000 }'
# The response is a GeoJSON FeatureCollection you can draw on the map.
# Other operations take the same datasetId:
# aggregate { "datasetId": "...", "groupBy": "province", "property": "staff" }
# aggregate { "datasetId": "...", "groupBy": "hex", "cellMeters": 5000 }
# nearest { "datasetId": "...", "lon": 100.54, "lat": 13.74, "k": 3 }
# intersect { "datasetIdA": "...", "datasetIdB": "..." }Draw the result
Analysis results are plain GeoJSON, so add them to a MapLibre map as a geojson source, or upload them as a new dataset to serve them as tiles.
// result = the GeoJSON FeatureCollection the analysis call returned
map.addSource("result", { type: "geojson", data: result })
map.addLayer({
id: "result-fill",
type: "fill",
source: "result",
paint: { "fill-color": "#b45309", "fill-opacity": 0.3 },
})Combine with the data catalog
The data catalog lists the Thailand layers MapScale publishes, such as hazard and reference layers. Read a layer's details to see how to use it, then run your analysis against it.
# Thailand data catalog: list layers, then read one layer's details.
curl "https://api.mapscale.io/v1/catalog" -H "x-api-key: sk_live_YOUR_SECRET_KEY"
curl "https://api.mapscale.io/v1/catalog/LAYER_ID" -H "x-api-key: sk_live_YOUR_SECRET_KEY"