Register New Fields
Description
The SpaceSense API let you register new fields using a specific json format called GeoJson
In this section you will learn what Geojson looks like and how to send it to the API
You will also learn how to update or delete existing Fields.
If you already know how to use the API you can checkout the API documention
Geojson
Geojson is an open standard format designed for representing simple geographical features using GPS coordinates.
GeoJson let you draw all different kinds of shapes or landmarks.
For the sake of this API's use you will only use GeoJson Polygon feature to register new fields.
Need more informations about GeoJson ? checkout those websites :
Create a Json body for the request
To register a new field you will need a GeoJson representing a polygon you can use Geojson.io to generate new Geojson.
Like this :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[3.431151509284973, 45.583409896815034],
[3.4310495853424072, 45.58235490155467],
[3.432530164718628, 45.58246002652684],
[3.432524800300598, 45.58345870394514],
[3.431151509284973, 45.583409896815034]
]
]
}
}
]
}
NOTE : The first part (type, features, properties, etc . . .) is part of the GeoJson format. Removing it will cause issues with the API.
Now that you know what a GeoJson looks like, let's register a new Field.
The Polygon is not the only information we need to give the API, you need to build a complete Json body for the request.
You need to add a Field name defined by a string and an array of all the labels you want for this field.
The final Json will look something like that :
{
"field_name": "farm_9",
"label": ["NDVI", "NDWI", "Farmer-34"],
"geojson": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-4.391269683837891, 39.71808094723828],
[-4.388244152069092, 39.71149505915214],
[-4.3865275382995605, 39.7120727937937],
[-4.387707710266113, 39.717800358315465],
[-4.391269683837891, 39.71808094723828]
]
]
}
}
]
}
}
You will use this json to register new fields.
Register new fields
To register a new Field you will need a Json string referred to as __myJsonBody__
in those examples.
You will also need your Identification token referred to as __myToken__
in those examples.
curl -h "Content-Type: application/json" -d __myJsonBody__ https://spacesense-api.ew.r.appspot.com/fields/register?token=__myToken__
#import requests & json libraries
import requests
import json
# Sends a post request using your identification Token and the Json previously built
r = requests.post('https://spacesense-api.ew.r.appspot.com/fields/register?token=' + __myToken__, json = json.loads(__myJsonBody__))
Update existing Fields
When a field is created you can now update it by changing the labels attached to it.
To do so you will send a basic Json with the field's name and a new array of labels.
The new label Array will replace the old one entirely.
Json example :
{
"field_name": "farm_9",
"label": ["NDVI", "NDWI", "Farmer-34"]
}
To update a Field you will need a Json string referred to as __myJsonBody__
in those examples.
You will also need your Identification token referred to as __myToken__
in those examples.
curl -h "Content-Type: application/json" -d __myJsonBody__ https://spacesense-api.ew.r.appspot.com/fields/update?token=__myToken__
#import requests & json libraries
import requests
import json
# Sends a post request using your identification Token and the Json previously built
r = requests.post('https://spacesense-api.ew.r.appspot.com/fields/update?token=' + __myToken__, json = json.loads(__myJsonBody__))
Delete existing Fields
You can Delete a previously created Field using a simple GET request.
To delete a Field you will need your Identification token referred to as __myToken__
in those examples.
And the Field's name referred to as __fieldName__
in those examples.
curl https://spacesense-api.ew.r.appspot.com/fields/delete/__fieldName__?token=__myToken__
#import requests & json libraries
import requests
# Sends a post request using your identification Token and the Json previously built
r = requests.get('https://spacesense-api.ew.r.appspot.com/fields/delete/__fieldName__?token=' + __myToken__)