Gfw Query
gfw_queryRun a read-only SQL SELECT against one Global Forest Watch dataset version — e.g. tree cover loss hectares by year inside an area, or deforestation alerts inside a bounding box. The table is always called data; use gfw_dataset to see the available columns first. Almost every GFW dataset (tree cover loss/gain, GLAD/RADD alerts, fire alerts, carbon, primary forest) is a RASTER TILE SET, not a plain table — a geometry (GeoJSON Polygon/MultiPolygon) is REQUIRED to scope the pixels queried, or the API answers 422 "Raster tile set queries require a geometry". Omit it only for the few vector-table datasets (e.g. wdpa_protected_areas). Requires your own free GFW API key, passed as _apiKey.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | A SELECT statement over the table `data`, e.g. "SELECT umd_tree_cover_loss__year, SUM(area__ha) AS loss_ha FROM data WHERE umd_tree_cover_loss__year > 0 GROUP BY umd_tree_cover_loss__year". SELECT only; a LIMIT is appended if you omit one. | |
| limit | No | Row cap appended when your SQL has no LIMIT (1-1000, default 100). | |
| _apiKey | Yes | Your own Global Forest Watch API key (BYO). Get one free at globalforestwatch.org: create an account, then POST /auth/token followed by POST /auth/apikey on data-api.globalforestwatch.org to mint an x-api-key. | |
| dataset | Yes | Dataset name, e.g. "umd_tree_cover_loss". | |
| version | No | Version, e.g. "latest" or "v1.13". Default "latest". | |
| geometry | No | GeoJSON Polygon or MultiPolygon ({"type":"Polygon","coordinates":[...]}) scoping the query spatially. REQUIRED for raster tile set datasets — which is most of them; see gfw_dataset's version_assets. Example, a ~0.2° box over Rondônia, Brazil: {"type":"Polygon","coordinates":[[[-63.0,-9.0],[-62.8,-9.0],[-62.8,-8.8],[-63.0,-8.8],[-63.0,-9.0]]]}. |