There are several methods of working with the Polygons API service: polygon creation, adding data, removing a polygon, listing info about one or several polygons. You can also find a list of your polygons on your account page.
We have a simple visual tool that can help to generate GeoJSON for your field. Draw a field with a square or polygon tool and get coordinates in a pop-up window. Copy them into a POST request.
http://api.agromonitoring.com/agro/1.0/polygons?appid=test
POST
Content-Type: application/json
appid
name
The name of your polygon
geo_json
Coordinates specify only in GeoJSON format - [lon, lat].
- Coordinates MUST follow the right-hand or left-hand rule with respect to the area it bounds.
- You can create the polygon with or without a hole. See the example how to create the polygon with a hole.
- There are several limitations:
- The type of geometry should be "Polygon"
- The polygon can not has self-intersections
- Limits of 1 - 3000 ha for the area of your polygon
duplicated
The Polygon API checks and blocks attempt to create polygons duplicates. If you need to create the same polygon, please pass the flag 'duplicated=true' to the query. See the example.
GeoJSON format is used to specify the geometry of the polygon. Please note that the coordinates of the points have the following order - longitude, latitude. You can learn more about this format in the RFC specification.
{ "name":"Polygon Sample", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } } }
201
{ "id":"5abb9fb82c8897000bde3e87", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } }, "name":"Polygon Sample", "center":[121.1867,37.6739], "area":190.6343, "user_id":"557066d0ff7a7e3897531d94" }
id
The internal ID of the polygon you get during creation (string), e.g. id=583d7bbbebb3ff000123f1ce
geo_json
Coordinates your polygon in GeoJSON format.
name
The name of your polygon
center
The central point of the polygon, the average of [lat, lon] over all points (array), e.g. center=[-121.1867,37.6739]
area
Area in hectares (float), e.g. area=190.6343
For the Free plan users: If you created your polygon on a territory that is not marked on the map of the price page, then please wait a few days before the data from the satellite is downloaded for your polygon.
The Polygon API checks and blocks attempt to create polygons duplicates. If you need to create the same polygon, please pass the flag 'duplicated=true' to the query. See the example below.
http://api.agromonitoring.com/agro/1.0/polygons?appid=test&duplicated=true
POST
Content-Type: application/json
{ "name":"Polygon Sample", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } } }
You can create a poligon with a hole. The first element in the array represents the exterior ring. Any subsequent elements represent interior holes.
http://api.agromonitoring.com/agro/1.0/polygons?appid=test
POST
Content-Type: application/json
{ "name":"Polygon Sample", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], [ [100.8, 0.8], [100.8, 0.2], [100.2, 0.2], [100.2, 0.8], [100.8, 0.8] ] ] } } }
The mistake was made in the section "coordinates" of request body. When creating a polygon, the first and last positions are equivalent, and they MUST contain identical values; their representation SHOULD also be identical.
http://api.agromonitoring.com/agro/1.0/polygons?appid=test
POST
Content-Type: application/json
{ "name":"Polygon Sample", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.668] ] ] } } }
422
{ "message": "Validation of Polygon failed. Summary: The following errors were found: Geo json is invalid. Invalid coordinates resolution: Try persisting the document with valid data or remove the validations." }
http://api.agromonitoring.com/agro/1.0/polygons/5abb9fb82c8897000bde3e87?appid=test
GET
200
{ "id":"5abb9fb82c8897000bde3e87", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } }, "name":"Polygon Sample", "center":[-121.1867,37.6739], "area":190.6343, "user_id":"557066d0ee7b3e3897531d94" }
Wrong id
is passed.
http://api.agromonitoring.com/agro/1.0/polygons/incorrect?appid=test
GET
{ "message":"\nmessage:\n Document(s) not found for class Polygon with id(s) incorrect.\nsummary:\n When calling Polygon.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): incorrect ... (1 total) and the following ids were not found: incorrect. \nresolution:\n Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples." }
http://api.agromonitoring.com/agro/1.0/polygons?appid=test
GET
200
[ { "id":"5abb9fb82c8897000bde3e87", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773, 37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } }, "name":"Polygon Sample", "center":[-121.1867,37.6739], "area":190.6343, "user_id":"557066d0ee7b3e3897531d94" } ]
In order to update info for a polygon the id
parameter should be used. Currently there is only available to update name
parameter, without changing polygon's area.
The geo_json
parameter is ignored in the API response.
http://api.agromonitoring.com/agro/1.0/polygons/5abb9fb82c8897000bde3e87?appid=test
PUT
Content-Type: application/json
{ "geo_json":{ "something":"something" }, "name":"Polygon New Name", }
200
{ "id":"5abb9fb82c8897000bde3e87", "geo_json":{ "type":"Feature", "properties":{ }, "geometry":{ "type":"Polygon", "coordinates":[ [ [-121.1958,37.6683], [-121.1779,37.6687], [-121.1773,37.6792], [-121.1958,37.6792], [-121.1958,37.6683] ] ] } }, "name":"Polygon New Name", "center":[121.1867, 37.6739], "area":190.6343, "user_id":"557066d0ff7a7e3897531d94" }
Wrong id
is passed or it is incorrectly typed.
http://api.agromonitoring.com/agro/1.0/polygons/incorrect?appid=test
PUT
Content-Type: application/json
404
{ "message":"\nmessage:\n Document(s) not found for class Polygon with id(s) incorrect.\nsummary:\n When calling Polygon.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): incorrect ... (1 total) and the following ids were not found: incorrect. \nresolution:\n Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples." }
In order to remove a polygon the id
parameter is used.
http://api.agromonitoring.com/agro/1.0/polygons/5abb9fb82c8897000bde3e87?appid=test
DELETE
204
— (means the API call is completed successfully)
Wrong id
is passed or it is incorrectly typed.
http://api.agromonitoring.com/agro/1.0/polygons/incorrect?appid=test
DELETE
404
{ "message":"\nmessage:\n Document(s) not found for class Polygon with id(s) incorrect.\nsummary:\n When calling Polygon.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): incorrect ... (1 total) and the following ids were not found: incorrect. \nresolution:\n Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples." }
2012 - 2024 AgroMonitoring © All rights reserved