Satellite Images

In this part we will focus on two endpoint:

  1. “/AFS/VegetationIndex” endpoint, which allow the user to get the latest vegetation index available for the Area of Interest in tiff format
  2. “/AFS/VegetationIndexGeojson” endpoint, which allow the user to get the latest vegetation index available for the Area of Interest in geojson format

VegetationIndex

Python

In this example we will test the VegetationIndex which allow the user to get the latest vegetation index available for the Area of Interest in tiff format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

Load Libraries

import requests
import rasterio
import rasterio.plot
import folium
from rasterio.warp import calculate_default_transform, reproject, Resampling
from requests.auth import HTTPBasicAuth

Setting of the API

# Define the vegetation index that you want

fieldnumber="1"
action="none"
vegetation_index="ndvi"
filterTime="onelastmonth"

# Define the url of the API

api_url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexNew?fieldnumber=",fieldnumber,"&action=",action,"&vegetationindex="+vegetation_index+"&filterTime="+filterTime

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Set the geojson file to send
geojson_file_path = "county.geojson"

Define python function

def convert_to_wgs84(input_raster_path, output_raster_path):
    # Open the input raster
    with rasterio.open(input_raster_path) as src:
        # Define the target CRS (WGS 84 - EPSG:4326)
        target_crs = 'EPSG:4326'

        # Get the affine transformation and dimensions of the new raster
        transform, width, height = calculate_default_transform(src.crs, target_crs, src.width, src.height, *src.bounds)

        # Create the options for reprojection
        kwargs = src.meta.copy()
        kwargs.update({
            'crs': target_crs,
            'transform': transform,
            'width': width,
            'height': height
        })

        # Reproject the raster to WGS 84
        with rasterio.open(output_raster_path, 'w', **kwargs) as dst:
            for i in range(1, src.count + 1):
                reproject(
                    source=rasterio.band(src, i),
                    destination=rasterio.band(dst, i),
                    src_transform=src.transform,
                    src_crs=src.crs,
                    dst_transform=transform,
                    dst_crs=target_crs,
                    resampling=Resampling.nearest
                )
def post_request_with_geojson(geojson_file_path, api_url):
    # Leggi il file GeoJSON
    with open(geojson_file_path, 'r') as file:
        geojson_data = file.read()

    # Specifica l'header per la POST request
    headers = {'Content-Type': 'application/json'}

    # Effettua la POST request
    response = requests.post(api_url, 
                             data=geojson_data, 
                             headers=headers,
                             auth=HTTPBasicAuth(USEREMAIL, APIKEY))
    
    if response.status_code == 200:
        # Save the response as a temporary raster file
        temp_raster_path = "temp_raster.tif"
        with open(temp_raster_path, 'wb') as temp_raster_file:
            temp_raster_file.write(response.content)

        # Convert the raster to WGS 84 (EPSG:4326)
        wgs84_raster_path = "temp_raster_wgs84.tif"
        convert_to_wgs84(temp_raster_path, wgs84_raster_path)

        # Open the WGS 84 raster using rasterio
        wgs84_raster = rasterio.open(wgs84_raster_path)

        # Read the image as a numpy array
        data = wgs84_raster.read(1)

        # Get the extent of the image
        xmin, ymin, xmax, ymax = wgs84_raster.bounds

        # Create a folium map centered at the center of the extent of the image
        center = [(ymin+ymax)/2, (xmin+xmax)/2]
        m = folium.Map(location=center, zoom_start=16)

        # Add the tif file as a raster layer
        overlay = folium.raster_layers.ImageOverlay(
            image=data,
            bounds=[[ymin, xmin], [ymax, xmax]],
            colormap=lambda x: (0, 0, 0, x/255),
            mercator_project=True)
        
        overlay.add_to(m)

        # Visualize the map
        return m
    else:
        print("Error during the request.")
        return None
# Make the POST request
m = post_request_with_geojson(geojson_file_path, api_url)

# Visualize the results

m

R

In this example we will test the VegetationIndex which allow the user to get the latest vegetation index available for the Area of Interest in tiff format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

# import libraries

library(tictoc)
library(httr)
library(gt)
library(tidyverse)
library(raster)
library(mapview)

# Define the API parameters setting

fieldnumber="1"
action="none"
vegetation_index="ndvi"
filterTime="onelastmonth"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexNew?fieldnumber=",fieldnumber, "&action=",action,"&vegetationindex=", vegetation_index, "&filterTime=",filterTime)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Path to the GeoJSON file

file_path_to_geojson = "county.geojson"

# Get the start time to API Call

tic()

# Make the POST request

r <- POST(
  api_url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  ),
  body=httr::upload_file(file_path_to_geojson)
)

# Print out the seconds needed to get the satellite image

print("The API needed:")
[1] "The API needed:"
toc()
3.46 sec elapsed
# Get the status of the request

httr::status_code(r)
[1] 200
# Visulize the vegetation index

bin_raster<-readBin(r$content, what = "raw", n=length(r$content))

writeBin(bin_raster, con = "raster.tif")

raster <- raster::raster("raster.tif")

mapview(raster, layer.name="NDVI")

Node.js

In this example we will test the VegetationIndex which allow the user to get the latest vegetation index available for the Area of Interest in tiff format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. geojsonFilePath (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

// load libraries

const axios = require('axios');
const fs = require('fs');

// Set the username & API key
const username = 'XXXXXXXXXXXXXXXXX';
const password = 'XXXXXXXXXXXXXXXXXXX';
const filterTime= 'onelastmonth';

// Set the API Parameters

const fieldnumber="1";
const action="none";
const vegetationindex='ndvi';
const filterTime="onelastmonth"

// Set api endpoint

const apiUrl = 'https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexNew?'; 

// Set api endpoint that we will use

const apiendpoint=apiUrl.concat("fieldnumber=",fieldnumber,, "&action=",action, "&vegetationindex=",vegetationindex, "&filterTime=", filterTime)

// Set the path to the local GeoJson that you want to use

const geojsonFilePath = './county.geojson';


// Set the path to save the raster that we will recive
const rasterFilePath = './file.tif';

async function makePostRequest() {

  const geojsonFile = fs.readFileSync(geojsonFilePath, 'utf8');

  const authHeader = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');

  try {
    const response = await axios.post(apiendpoint, geojsonFile, {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': authHeader,
      },
      responseType: 'arraybuffer',
    });
    
    fs.writeFileSync(rasterFilePath, response.data);

    console.log('The raster file was locally saved', rasterFilePath);
  } catch (error) {
    console.error('An error occurred:', error.message);
  }
}

makePostRequest();

Java

In this example we will test the VegetationIndex which allow the user to get the latest vegetation index available for the Area of Interest in tiff format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. geojsonFilePath (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;


public class VegetationIndex {
    public static void main(String[] args) {
        String apiUrl = "https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexNew?fieldnumber=1&action=new&vegetationindex=ndvi&filterTime=onelastmonth";
        String username = "XXXXXXXXXXXXXXXXXXXXXX";
        String password = "XXXXXXXXXXXXXXXXXX";

        String geojsonFilePath = "county.geojson";
        String geojsonFile = "";
        try {
            geojsonFile = new String(Files.readAllBytes(Paths.get(geojsonFilePath)));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Imposta l'header per l'autenticazione base
        String authHeader = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes());

        try {
            // Effettua la richiesta POST all'API
            URL url = new URL(apiUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("Authorization", authHeader);
            conn.setDoOutput(true);

            OutputStream os = conn.getOutputStream();
            os.write(geojsonFile.getBytes());
            os.flush();

            // Gestisci la risposta
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                // Salva il file raster ottenuto in risposta
                String rasterFilePath = "raster_file.tif"; // Sostituisci con il percorso in cui vuoi salvare il file raster
                try (InputStream is = conn.getInputStream(); FileOutputStream fos = new FileOutputStream(rasterFilePath)) {
                    byte[] buffer = new byte[1024];
                    int bytesRead;
                    while ((bytesRead = is.read(buffer)) != -1) {
                        fos.write(buffer, 0, bytesRead);
                    }
                }

                System.out.println("The raster file it was saved correctly: " + rasterFilePath);
            } else {
                System.out.println("An error occured: " + conn.getResponseMessage());
            }

            conn.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

VegetationIndexGeojson

Python

In this example we will test the VegetationIndexGeojson which allow the user to get the latest vegetation index available for the Area of Interest in gejson format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

# Load the libraries

import requests
import fiona
import geopandas as gpd
from requests.auth import HTTPBasicAuth

# Define the API call parameters

fieldnumber="1"
action="none"
vegetation_index="ndvi"
filterTime="onelastmonth"

# Define the url of the API

api_url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexGeojsonNew?fieldnumber=",fieldnumber,"&action=",action,"&vegetationindex="+vegetation_index+"&filterTime="+filterTime

# Set the useremail & Password

USEREMAIL="email"
APIKEY="password"

# Path to the GeoJSON file

file_path_to_geojson = "county.geojson"

# Read the GeoJSON file contents

with open(file_path_to_geojson, "r") as file:
    geojson_data = file.read()

# Set the headers for the request

headers = {
    "Content-Type": "application/json"
}

# Make the POST request with the GeoJSON data as the request body

response = requests.post(url, 
                         data=geojson_data, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

b = bytes(response.content)

with fiona.BytesCollection(b) as f:
    crs = f.crs
    gdf = gpd.GeoDataFrame.from_features(f, crs=crs)

#  Visualize the data

gdf.explore("Data_2023.07.19")

R

In this example we will test the VegetationIndexGeojson which allow the user to get the latest vegetation index available for the Area of Interest in gejson format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

# Load the libraries

library(tictoc)
library(httr)
library(geojsonio)
library(mapview)

# Define the API parameters setting

fieldnumber="1"
action="none"
vegetation_index="ndvi"
filterTime="onelastmonth"

# Define the url of the API

url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexGeojsonNew?fieldnumber=",fieldnumber, "&action=",action,"&vegetationindex=", vegetation_index, "&filterTime=",filterTime)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Path to the GeoJSON file

file_path_to_geojson = "county.geojson"

# Get the start time to API Call

tic()

# Make the POST request

api_call <- POST(
  url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  ),
  body=httr::upload_file(file_path_to_geojson)
)

# Print out the seconds needed to create the prescription map

print("The API needed:")
[1] "The API needed:"
toc()
2.41 sec elapsed
# Visualize the prescription map

vegetation_index <- content(api_call, as = "text", type = "application/geo+json")
vegetation_index<-geojson_sp(vegetation_index)
mapview(vegetation_index, zcol=names(vegetation_index)[1])

Node.js

In this example we will test the VegetationIndexGeojson which allow the user to get the latest vegetation index available for the Area of Interest in gejson format

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. filterTime, Set the date filter can be onelastmonth, twolastmonth or none
  7. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

// Load Libraries

const fs = require('fs');
const axios = require('axios');

// Set the useremail & passowrd

const useremail = 'XXXXXXXXXXXXX';
const apikey = 'XXXXXXXXXXXXX';

// Set the API Parameters

const fieldnumber="1";
const action="none";
const vegetationindex='ndvi';
const filterTime="onelastmonth"

// Set api endpoint

const apiUrl = 'https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexGeojsonNew?'; 

// Set api endpoint that we will use

const apiEndpoint=apiUrl.concat("fieldnumber=",fieldnumber,, "&action=",action, "&vegetationindex=",vegetationindex, "&filterTime=", filterTime)

// Set path to load the geojson to send as body of POST request to the API

const file_path_to_geojson = './county.geojson';

// Set path to save the geojson prescription map

const outputFilePath = './result.geojson'; 

(async () => {
  try {

    const geojsonContent = await fs.promises.readFile(file_path_to_geojson, 'utf8');
    
    const geojsonObject = JSON.parse(geojsonContent);

    
    const authHeader = `Basic ${Buffer.from(`${useremail}:${apikey}`).toString('base64')}`;

    
    const response = await axios.post(apiEndpoint, geojsonObject, {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': authHeader
      }
    });

    const resultGeoJSON = response.data;
    
    console.log('Answer From the API:', resultGeoJSON);

    await fs.promises.writeFile(outputFilePath, JSON.stringify(resultGeoJSON, null, 2), 'utf8');

  } catch (err) {
    console.error('Error:', err.message);
  }
})();

Java

Work in progress

VegetationIndexTemporalVariationJson

Python

In this example we will test the VegetationIndexTemporalVariationJson which allow the user to get a json with the temporal variation of the vegetation index.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

# Load the libraries

import requests
import json
import pandas as pd
from requests.auth import HTTPBasicAuth


# Define the vegetation index that you want

fieldnumber="1"
action="none"
vegetation_index="ndvi"

# Define the url of the API

api_url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexTemporalVariationJsonNew?fieldnumber=",fieldnumber,"&action=",action,"&vegetationindex="+vegetation_index

# Set the useremail & Password

USEREMAIL="XXXXXXXXXXXX"
APIKEY="XXXXXXX"

# Path to the GeoJSON file

file_path_to_geojson = "county.geojson"

# Read the GeoJSON file contents

with open(file_path_to_geojson, "r") as file:
    geojson_data = file.read()

# Set the headers for the request

headers = {
    "Content-Type": "application/json"
}

# Make the POST request with the GeoJSON data as the request body

response = requests.post(url, 
                         data=geojson_data, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

response_bytes=response.content

response_str = response_bytes.decode('utf-8')

# Parse the JSON string
data = json.loads(response_str)

# Create a DataFrame
df = pd.DataFrame(data)

df.head()

R

In this example we will test the VegetationIndexTemporalVariationJson which allow the user to get a json with the temporal variation of the vegetation index.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

# Load the libraries

library(tictoc)
library(httr)
library(geojsonio)
library(mapview)

# Define the API parameters setting

fieldnumber="1"
action="none"
vegetation_index="ndvi"

# Define the url of the API

url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexTemporalVariationJsonNew?fieldnumber=",fieldnumber, "&action=",action,"&vegetationindex=", vegetation_index)


# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Path to the GeoJSON file

file_path_to_geojson = "county.geojson"

# Get the start time to API Call

tic()

# Make the POST request

api_call <- POST(
  url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  ),
  body=httr::upload_file(file_path_to_geojson)
)

# Print out the seconds needed to create the prescription map

print("The API needed:")
[1] "The API needed:"
toc()
2.19 sec elapsed
# Visualize the prescription map
cont <- httr::content(api_call, as = "text", type = "application/json", encoding="UTF-8")
cont<-jsonlite::fromJSON(cont) %>% as.data.frame
cont
     layer
1   0.1732
2   0.1827
3   0.1295
4   0.1653
5   0.2182
6   0.0924
7   0.1124
8   0.1569
9   0.0890
10  0.0911
11  0.1034
12  0.1576
13  0.0941
14  0.1170
15  0.0932
16  0.1003
17  0.0865
18  0.0955
19  0.0946
20  0.0945
21  0.1357
22  0.1610
23  0.1320
24  0.1279
25  0.1598
26  0.2053
27  0.1071
28  0.0994
29  0.0932
30  0.0877
31  0.0774
32  0.0773
33  0.0858
34  0.0996
35  0.2267
36  0.0991
37  0.0919
38  0.0934
39  0.1026
40  0.1182
41  0.1096
42  0.0979
43  0.0970
44  0.1095
45  0.1296
46  0.1660
47  0.2232
48  0.0966
49  0.0984
50  0.1006
51  0.0943
52  0.0903
53  0.0897
54  0.0875
55  0.0880
56  0.0849
57  0.0886
58  0.1008
59  0.1198
60  0.1947
61  0.2105
62  0.2577
63  0.1542
64  0.1978
65  0.2749
66  0.1814
67  0.0949
68  0.0893
69  0.0909
70  0.0866
71  0.0771
72  0.0774
73  0.0821
74  0.0840
75  0.0828
76  0.0789
77  0.0876
78  0.1160
79  0.1693
80  0.2084
81  0.2007
82  0.1313
83  0.1001
84  0.0862
85  0.0905
86  0.1009
87  0.1000
88  0.0976
89  0.0973
90  0.0905
91  0.0876
92  0.0944
93  0.0941
94  0.0947
95  0.0959
96  0.1035
97  0.1261
98  0.1477
99  0.1573
100 0.1534
101 0.1571
102 0.1422
103 0.1215
104 0.1522
105 0.2159
106 0.1628
107 0.1266
108 0.1676
109 0.1549
110 0.1165
111 0.0880
112 0.0868
113 0.0887
114 0.0818
115 0.0733
116 0.0739
117 0.0779
118 0.0777
119 0.0765
120 0.0758
121 0.0768
122 0.0981
123 0.1435
124 0.1718
125 0.1680
126 0.1525
127 0.1459
128 0.1493
129 0.1722
130 0.1616
131 0.1415
132 0.1224
133 0.1081
134 0.0935
135 0.0737
136 0.0762
137 0.0893
138 0.1031
139 0.1024
140 0.0985
141 0.0935
142 0.0930
143 0.0909
144 0.0939
145 0.0973
146 0.0998
147 0.0942
148 0.0924
149 0.0980
150 0.1022
151 0.1007
152 0.0891
153 0.0813
154 0.0821
155 0.0838
156 0.0926
157 0.1229
158 0.1232
159 0.1018
160 0.0992
161 0.0935
162 0.0867
163 0.0827
164 0.0843
165 0.0830
166 0.0751
167 0.0734
168 0.0724
169 0.0725
170 0.0698
171 0.0687
172 0.0720
173 0.0720
174 0.0953
175 0.1482
176 0.1713
177 0.1792
178 0.1804
179 0.1722
180 0.1714
181 0.1786
182 0.1479
183 0.1322
184 0.1175
185 0.1097
186 0.1018
187 0.0972
188 0.1016
189 0.0991
190 0.0972
191 0.0859
192 0.0754
193 0.0789
194 0.0904
195 0.1041
196 0.1039
197 0.1002
198 0.0952
199 0.0954
200 0.0978
201 0.0991
202 0.0998
203 0.0968
204 0.0923
205 0.0883
206 0.0843
207 0.0827
208 0.0834
209 0.0785
210 0.0722
211 0.0707
212 0.0730
213 0.0759
214 0.0852
215 0.0848
216 0.0800
217 0.0808
218 0.0823
219 0.0821
220 0.0843
221 0.0841
222 0.0808
223 0.0762
224 0.0752
225 0.0724
226 0.0674
227 0.0635
228 0.0668
229 0.0728
230 0.0770
231 0.1036
232 0.1461
233 0.1638
234 0.1814
235 0.1930
236 0.1853
237 0.1854
238 0.1840
239 0.1623
240 0.1338
241 0.1190
242 0.1105
243 0.1005
244 0.0976
245 0.0924
246 0.0908
247 0.0888
248 0.0913
249 0.0952
250 0.0936
251 0.0934
252 0.0859
253 0.0811
254 0.0858
255 0.0984
256 0.1079
257 0.1055
258 0.1014
259 0.0928
260 0.0912
261 0.0931
262 0.0941
263 0.0892
264 0.0881
265 0.0850
266 0.0830
267 0.0795
268 0.0790
269 0.0794
270 0.0753
271 0.0702
272 0.0683
273 0.0725
274 0.0763
275 0.0796
276 0.0782
277 0.0764
278 0.0739
279 0.0780
280 0.0848
281 0.0858
282 0.0837
283 0.0796
284 0.0763
285 0.0758
286 0.0745
287 0.0676
288 0.0655
289 0.0721
290 0.0751
291 0.0804
292 0.1135
293 0.1554
294 0.1719
295 0.1820
296 0.1795
297 0.1704
298 0.2449
299 0.2032
300 0.1548
301 0.1486
302 0.1369
303 0.1204
304 0.1084
305 0.1012
306 0.0949
307 0.0928
308 0.0956
309 0.0886
310 0.0848
311 0.0861
312 0.0896
313 0.0916
314 0.0900
315 0.0899
316 0.0867
317 0.0851
318 0.0887
319 0.0996
320 0.1024
321 0.1015
322 0.0983
323 0.0843
324 0.0849
325 0.0889
326 0.0832
327 0.0769
328 0.0825
329 0.0821
330 0.0807
331 0.0817
332 0.0831
333 0.0839
334 0.0808
335 0.0765
336 0.0726
337 0.0717
338 0.0754
339 0.0796
340 0.0785
341 0.0777
342 0.0780
343 0.0790
344 0.0821
345 0.0836
346 0.0841
347 0.0815
348 0.0803
349 0.0766
350 0.0726
351 0.0731
352 0.0738
353 0.0787
354 0.0841
355 0.0920
356 0.1267
357 0.1645
358 0.1832
359 0.1871
360 0.1817
361 0.2057
362 0.1510
363 0.1256
364 0.1172
365 0.1127
366 0.1100
367 0.1024
368 0.0936
369 0.0920
370 0.0946
371 0.0968
372 0.0926
373 0.0902
374 0.0862
375 0.0883
376 0.0926
377 0.0910
378 0.0902
379 0.0889
380 0.0895
381 0.0953
382 0.1024
383 0.1016
384 0.0971
385 0.0876
386 0.0779
387 0.0762
388 0.0812
389 0.0824
390 0.0821
391 0.0813
392 0.0805
393 0.0812
394 0.0829
395 0.0862
396 0.0896
397 0.0877
398 0.0824
399 0.0762
400 0.0709
401 0.0735
402 0.0788
403 0.0794
404 0.0808
405 0.0820
406 0.0803
407 0.0793
408 0.0795
409 0.0795
410 0.0783
411 0.0821
412 0.0764
413 0.0700
414 0.0722
415 0.0778
416 0.0820
417 0.0842
418 0.1000
419 0.1466
420 0.1904
421 0.2051
422 0.2130
423 0.1256
424 0.1139
425 0.1114
426 0.1043
427 0.1027
428 0.1005
429 0.0952
430 0.0941
431 0.0955
432 0.1002
433 0.0985
434 0.0948
435 0.0931
436 0.0929
437 0.0939
438 0.0917
439 0.0883
440 0.0833
441 0.0850
442 0.0961
443 0.1001
444 0.0987
445 0.0910
446 0.0785
447 0.0720
448 0.0705
449 0.0718
450 0.0751
451 0.0780
452 0.0793
453 0.0809
454 0.0851
455 0.0860
456 0.0893
457 0.0912
458 0.0884
459 0.0828
460 0.0753
461 0.0716
462 0.0743
463 0.0796
464 0.0795
465 0.0799
466 0.0809
467 0.0795
468 0.0800
469 0.0779
470 0.0736
471 0.0702
472 0.0732
473 0.0724
474 0.0712
475 0.0747
476 0.0770
477 0.0771
478 0.0840
479 0.1121
480 0.1708
481 0.2112
482 0.2230
483 0.2710
484 0.1310
485 0.1144
486 0.1107
487 0.1050
488 0.0984
489 0.1006
490 0.0991
491 0.0977
492 0.0962
493 0.1000
494 0.1013
495 0.0978
496 0.0930
497 0.0857
498 0.0833
499 0.0834
500 0.0814
501 0.0791
502 0.0827
503 0.0938
504 0.0968
505 0.0947
506 0.0860
507 0.0771
508 0.0704
509 0.0686
510 0.0730
511 0.0781
512 0.0768
513 0.0790
514 0.0867
515 0.0896
516 0.0869
517 0.0887
518 0.0872
519 0.0857
520 0.0828
521 0.0744
522 0.0694
523 0.0727
524 0.0779
525 0.0758
526 0.0738
527 0.0753
528 0.0768
529 0.0803
530 0.0761
531 0.0706
532 0.0625
533 0.0653
534 0.0725
535 0.0723
536 0.0730
537 0.0775
538 0.0819
539 0.0890
540 0.1204
541 0.1782
542 0.2261
543 0.2906
544 0.1225
545 0.1148
546 0.1069
547 0.1055
548 0.1005
549 0.0984
550 0.0962
551 0.0946
552 0.0907
553 0.0928
554 0.0977
555 0.0993
556 0.0946
557 0.0839
558 0.0798
559 0.0843
560 0.0865
561 0.0850
562 0.0851
563 0.0921
564 0.0926
565 0.0864
566 0.0800
567 0.0758
568 0.0723
569 0.0709
570 0.0764
571 0.0781
572 0.0750
573 0.0784
574 0.0875
575 0.0895
576 0.0856
577 0.0844
578 0.0838
579 0.0851
580 0.0841
581 0.0774
582 0.0721
583 0.0753
584 0.0779
585 0.0736
586 0.0726
587 0.0749
588 0.0785
589 0.0831
590 0.0789
591 0.0726
592 0.0637
593 0.0676
594 0.0744
595 0.0752
596 0.0741
597 0.0767
598 0.0844
599 0.0975
600 0.1359
601 0.1919
602 0.2635
603 0.3065
604 0.1319
605 0.1165
606 0.1055
607 0.1057
608 0.1042
609 0.1009
610 0.0975
611 0.0922
612 0.0924
613 0.1006
614 0.1036
615 0.1019
616 0.0956
617 0.0897
618 0.0867
619 0.0844
620 0.0844
621 0.0872
622 0.0922
623 0.0931
624 0.0881
625 0.0800
626 0.0764
627 0.0732
628 0.0701
629 0.0698
630 0.0758
631 0.0752
632 0.0724
633 0.0774
634 0.0828
635 0.0863
636 0.0837
637 0.0830
638 0.0841
639 0.0844
640 0.0843
641 0.0800
642 0.0766
643 0.0800
644 0.0840
645 0.0790
646 0.0760
647 0.0775
648 0.0789
649 0.0837
650 0.0816
651 0.0763
652 0.0710
653 0.0709
654 0.0721
655 0.0750
656 0.0756
657 0.0783
658 0.0858
659 0.1051
660 0.1597
661 0.2296
662 0.3095
663 0.1147
664 0.1069
665 0.1061
666 0.1059
667 0.1053
668 0.1089
669 0.1098
670 0.1068
671 0.1078
672 0.1090
673 0.1055
674 0.0971
675 0.0922
676 0.0904
677 0.0872
678 0.0881
679 0.0905
680 0.0917
681 0.0881
682 0.0836
683 0.0776
684 0.0735
685 0.0708
686 0.0702
687 0.0706
688 0.0754
689 0.0773
690 0.0772
691 0.0807
692 0.0822
693 0.0840
694 0.0786
695 0.0808
696 0.0821
697 0.0803
698 0.0788
699 0.0783
700 0.0790
701 0.0820
702 0.0906
703 0.0886
704 0.0831
705 0.0822
706 0.0834
707 0.0866
708 0.0829
709 0.0744
710 0.0757
711 0.0776
712 0.0796
713 0.0879
714 0.0895
715 0.0886
716 0.0907
717 0.1139
718 0.1717
719 0.2302
720 0.1241
721 0.1046
722 0.1087
723 0.1090
724 0.1064
725 0.1073
726 0.1106
727 0.1089
728 0.1064
729 0.1043
730 0.1028
731 0.0992
732 0.0958
733 0.0962
734 0.0933
735 0.0946
736 0.0948
737 0.0942
738 0.0874
739 0.0820
740 0.0759
741 0.0690
742 0.0658
743 0.0687
744 0.0718
745 0.0761
746 0.0812
747 0.0832
748 0.0832
749 0.0848
750 0.0872
751 0.0841
752 0.0826
753 0.0803
754 0.0793
755 0.0775
756 0.0794
757 0.0811
758 0.0810
759 0.0877
760 0.0900
761 0.0866
762 0.0865
763 0.0941
764 0.0974
765 0.0888
766 0.0816
767 0.0841
768 0.0843
769 0.0813
770 0.0895
771 0.0974
772 0.0980
773 0.0939
774 0.1151
775 0.1361
776 0.1154
777 0.1125
778 0.1116
779 0.1106
780 0.1079
781 0.1112
782 0.1133
783 0.1104
784 0.1087
785 0.1087
786 0.1053
787 0.1003
788 0.0986
789 0.0982
790 0.0968
791 0.0992
792 0.0972
793 0.0859
794 0.0820
795 0.0809
796 0.0740
797 0.0669
798 0.0718
799 0.0780
800 0.0784
801 0.0785
802 0.0817
803 0.0852
804 0.0886
805 0.0918
806 0.0911
807 0.0860
808 0.0825
809 0.0832
810 0.0848
811 0.0841
812 0.0799
813 0.0799
814 0.0858
815 0.0886
816 0.0872
817 0.0893
818 0.0939
819 0.0971
820 0.0915
821 0.0927
822 0.0903
823 0.0862
824 0.1302
825 0.1262
826 0.1210
827 0.1202
828 0.1204
829 0.1200
830 0.1197
831 0.1173
832 0.1127
833 0.1104
834 0.1094
835 0.1101
836 0.1097
837 0.1070
838 0.1059
839 0.1038
840 0.1058
841 0.1049
842 0.0988
843 0.0914
844 0.0885
845 0.0844
846 0.0801
847 0.0819
848 0.0846
849 0.0845
850 0.0831
851 0.0852
852 0.0896
853 0.0944
854 0.0960
855 0.0938
856 0.0918
857 0.0879
858 0.0863
859 0.0912
860 0.0885
861 0.0804
862 0.0832
863 0.0916
864 0.0910
865 0.0882
866 0.0908
867 0.0907
868 0.1510
869 0.1366
870 0.1242
871 0.1238
872 0.1221
873 0.1250
874 0.1252
875 0.1212
876 0.1207
877 0.1210
878 0.1204
879 0.1183
880 0.1114
881 0.1067
882 0.1107
883 0.1150
884 0.1135
885 0.1030
886 0.0953
887 0.0937
888 0.0905
889 0.0855
890 0.0885
891 0.1474
892 0.1218
893 0.1190
894 0.1171
895 0.1237
896 0.1243
897 0.1208
898 0.1226
899 0.1150
900 0.1124
901 0.1176
902 0.1219
903 0.1141
904 0.1095
905 0.1198
906 0.1236
907 0.1148
908 0.1041
909 0.1002
910 0.0989
911 0.1513
912 0.1212
913 0.1150
914 0.1043
915 0.1051
916 0.1070
917 0.0930
918 0.0857
919 0.0945
920 0.1047
921 0.1090
922 0.1009
923 0.0857
924 0.0984
925 0.1207
926 0.1244
927 0.1232
928 0.1494
929 0.1193
930 0.1203
931 0.1147
932 0.0930
933 0.0919
934 0.1180
935 0.1337
936 0.1464
937 0.1717
938 0.1839
939 0.1897
940 0.1337
941 0.1210
942 0.1044
943 0.0916

Node.js

In this example we will test the VegetationIndexTemporalVariationJson which allow the user to get a json with the temporal variation of the vegetation index.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, The field number. You have to refereed to the field that you can get from the gid column of the UserField endpoint response
  4. action, the action must be setted as none, new, edit. If you want to receive the data based on the polygons saved in the past set none. If you want to add a new field set as new. If you want to change the shape of the polygons set edit.
  5. vegetationindex, The name of vegetation index that you want (could be one of the follow vegetation indexes ndvi,evi2,msavi2,ipvi,msr,osavi,savi,tdvi,gari,arvi,evi,gci,gndvi,gosavi,grvi,nnir,gsavi,vdvi,wdrvi)
  6. file_path_to_geojson (you can find it here county.geojson the county file of the example)

With your information and let’s try out the API.

// Load Libraries

const fs = require('fs');
const axios = require('axios');


// set the username and apikey
const useremail = 'XXXXXXXXXXXX';
const apikey = 'XXXXXXXXXXXX';

// Set the API Parameters

const fieldnumber="1";
const action="none";
const vegetationindex='ndvi';

// Set api endpoint

const apiUrl = 'https://www.api.automaticfarmsolutionwebapp.com/AFS/VegetationIndexTemporalVariationJsonNew?'; 

// Set api endpoint that we will use

const api_endpoint=apiUrl.concat("fieldnumber=",fieldnumber,, "&action=",action, "&vegetationindex=",vegetationindex)

const file_path_to_geojson = './county.geojson';

async function main() {
  try {
    const geojson = JSON.parse(fs.readFileSync(file_path_to_geojson, 'utf8'));
    const authHeader = `Basic ${Buffer.from(`${useremail}:${apikey}`).toString('base64')}`;

    const response = await axios.post(api_endpoint, geojson, {
      headers: {
        Authorization: authHeader,
        'Content-Type': 'application/json',
      },
    });

    // Print the formatted JSON response to the console
    console.log(JSON.stringify(response.data, null, 2));
  } catch (error) {
    console.error('An error occurred:', error.message);
  }
}

main();

Java

Work in progress

Easy - Fast - Customizable

Back to top