Dive into Agro API | Part 2 - Polygons

Dive into Agro API  |  Part 2 - Polygons

Posted on 06 Aug 2018

By: Maxim Samokhin
Backend Developer, OpenWeather

This article is a step-by-step description of how to work with polygons using our instruments QueryBuilder and Agro API. The previous part explained to you how to use your personal account of the OpenWeather company, be sure to use it before starting to read this article. 

For working with the Agro API, you need to create polygons (in GeoJSON format) with your fields or areas of interest.  The methods of working with polygons, such as deleting, receiving, and updating, will be discussed below.  You can refer to our documentation  for more details. To make it easy to work with our documentation, please read the step-by-step description:

1) To create your polygon you can use our tile service QueryBuilder (Img. 1)

Otherwise, if you have already created polygons of fields or observation zones in GeoJSON format - go to step 3.

Img. 1. Query Builder


2) Now you need to find the area of your interest on the map, click on the polygon drawing button (Img. 2).

Img. 2. Query Builder Toolbar

3) Select your necessary area on the map (Img. 3)

Img. 3. Query Builder Toolbar

4) By clicking on the "VIEW POLYGON GEOJSON" button (Img. 2), you will receive a prepared polygon in the GeoJSON format in (on) the pop-up window (Img. 4).

Img. 4. Query Builder GeoJSON preview

For all steps below you need to use HTTP request methods.

5) Append created polygon.

This method is using to add your polygon in GeoJSON format to the Agro API service, which prepared in the previous paragraph. 

You need to make a POST request like this: 

http://api.agromonitoring.com/agro/1.0/polygons?appid={appid}


  Parameter

  Description

  appid

  Your "API Key" from the personal account 


Body of the POST request must contains a JSON format structure of the following form: 


Img. 5. POST request in JSON format

In response, you will get the JSON format structure of the following form:

Img. 6. Response in JSON format


6) Get information about one created polygon.

This method is using to receive information about one created polygon in the Agro API system

You need to make a GET request like this: 

http://api.agromonitoring.com/agro/1.0/polygons/{polygon_id}?appid={appid}


   Parameter

  Description

  appid

  Your "API Key" from the personal account 

  polygon_id

  “id” parameter that is contained in the response from the 5 step


In response, you will get the JSON format structure of the following form:


Img. 7. Response in JSON format


7) Get information about all created polygons.

This method is using to receive information about all created polygons in the Agro API system.

You need to make a GET request like this: 

http://api.agromonitoring.com/agro/1.0/polygons?appid={appid}


  Parameter

  Description

  appid

  Your "API Key" from the personal account


In response, you will get the JSON format structure of the following form with the list with all your polygons:


Img. 8. Response in JSON format


8) Update information about one created polygon.

This method is using to update information about one added polygon in the Agro API system.

You need to make a PUT request like this: 

http://api.agromonitoring.com/agro/1.0/polygons/{polygon_id}?appid={appid}


  Parameter

  Description

  appid

  Your "API Key" from the personal account 

  polygon_id

  “id” parameter that is contained in the response from the 5 and 7 steps


Body of the PUT request must contains a JSON format structure of the following form:

Img. 9. PUT request in JSON format

Please note: You can update only “name” field in your polygon information. Other fields from your PUT request will be ignored.

In response, you will get the JSON format structure of the following form with your new updated parameters:



Img. 10. Response in JSON format

9) Remove one created polygon.

This method is using to remove one created polygon from the Agro API system.

Then you need to make a GET request like this: 

http://api.agromonitoring.com/agro/1.0/polygons/{polygon_id}?appid={appid}


  Parameter

  Description

  appid

  Your "API Key" from the personal account 

  polygon_id

  “id” parameter that is contained in the response from the 5 and 7 steps


To know more detailed information about Agro API service requests (response codes, API request errors descriptions and other), please refer to our documentation.

In the next articles we will explain what operations with polygons you can do and what information you can get from the Agro API.