Querying a geospatial layer
One of the primary ways we expect users to make use of the Geospatial API is making a search on a single data set. Below we have outlined an example flow that you might use to get hold of the required data.
Step 1: Finding the Data Set ID
The first thing you will need to do is locate a geospatial data set by searching the marketplace.
Once you have found the appropriate data set, you will need to grab the data set ID from the Technical Attributes section seen below.
Step 2: Required Credentials
To call the Geospatial API you need:
- your
api-key
, found by following this guide. - a valid Agrimetrics JWT, found using the Get JWT endpoint.
Step 3: Getting the layer ID
Once you have your data set id and credentials, you can query the Geospatial API to get a list of layer ids.
Step 4: Find the Geospatial Extent
To get the geospatial extent of the given layer you can call the layers endpoint. Your new polygon might look something like this:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0.3302764892578125,
51.94077278761243
],
[
0.3335380554199219,
51.930189032251064
],
[
0.34709930419921875,
51.92394344554469
],
[
0.3635787963867187,
51.92817783649208
],
[
0.36083221435546875,
51.941513556993755
],
[
0.3302764892578125,
51.94077278761243
]
]
]
}
}
Step 5: Querying the Geospatial Layer
Once you have the bounding box of the layer, you will be able to query the data. In order to perform a search within the geospatial extent found, you will now need a bounding box or a polygon. You can do this via Geojson.io. You can then pass the created polygon into the search endpoint. This example is using the full bounding box received from the previous request.
const options = {
method: 'POST',
headers: {
accept: '*/*',
'content-type': 'application/json',
authorization: 'Bearer 9d7e80a0-ad76-4a5c'
},
body: JSON.stringify({
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0.3302764892578125,
51.94077278761243
],
[
0.3335380554199219,
51.930189032251064
],
[
0.34709930419921875,
51.92394344554469
],
[
0.3635787963867187,
51.92817783649208
],
[
0.36083221435546875,
51.941513556993755
],
[
0.3302764892578125,
51.94077278761243
]
]
]
},
"outputFormat": "application/json"
})
};
fetch('https://api.agrimetrics.co.uk/geospatial/layers/97130f06-6242-463f-bf19-0dd6f5a58cfb/search', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Output format
You can specify the format of the data that you would like to receive. Which format you can use will depend on the type of data that exists on the layer that you are querying.
For raster layers, you can request the data back as
image/tiff
.
For vector layers, you can request the data back asshape-zip
,application/json
,csv
,GML3
.
Updated almost 2 years ago