Swift Agro API library for satellite imagery

What's New

ios and macos


ios and macos targets

Swift OpenWeather Agro API library

OpenWeather Agro API brings satellite images to farmers. "Through our simple and fast API, you can easily get multi-spectrum images of the crop for the most recent day or for a day in the past; we have the most useful images for agriculture such as NDVI, EVI, True Color and False Color."

The concept in using Agro API satellite imagery is to first create one or more polygons representing for example, agricultural crop fields or forestry areas. Once the polygons are setup, satellite images such as; true color, false color, NDVI, EVI etc... can be retrieved from the Argo API server for those polygons. Those images are used to estimate the amount and health of the vegetation and crop development over time in those polygons.

AgroApi is a small Swift library to connect to the OpenWeather Agro API and retrieve the chosen data. Made easy to use with SwiftUI.

Includes, the Polygons, Weather, Satellite Imagery and Historical NDVI APIs.

Polygons API

The Agro Polygons API provides for polygon creation, adding data, removing a polygon and listing information about one or more polygons. You can also retrieve the list of all polygons from your account page.

Reference: Polygons

Satellite Imagery API

After the creation of polygons, the satellite imagery can be used for retrieving images for those polygons, such as; images in True Color, False Color, NDVI, and EVI in png, and get the meta data for your polygon or image in tiff.

Reference: Satellite Imagery

Agro weather API

The Agro weather API provides information on the current, forecast and historical weather for your polygons.

Reference: Current weather

Reference: Forecast weather

Reference: Historical weather

Agro historical NDVI API

The Agro historical NDVI API provides for previously observed (historical) NDVI values for your polygons.

Reference: Historical NDVI API

Reference: Historical NDVI API by polygon


All interactions with the Agro API server is done through the use of a single AgroProvider.

Data, such as satellite imagery from Agro API is accessed through the AgroProvider using a set of simple asynchronous functions, for example:

import AgroApi

struct ContentView: View {
    let agroProvider = AgroProvider(apiKey: "your key")
    @State var uiImage = UIImage()
    var body: some View {
        Image(uiImage: uiImage).onAppear { self.loadData() }
    func loadData() {
       let options = AgroOptions(polygon_id: "5f45273c734b52667be0bb1e",
                          start: Date().addingTimeInterval(-60*60*24*20),
                          end: Date())

       agroProvider.getImagery(options: options) { imagery in
          if let sat = imagery?.first, let img = sat.image, let theUrl = img.ndvi {
             self.agroProvider.getPngUIImage(urlString: theUrl, paletteid: 1, reponse: self.$uiImage)

For example use, see:

AgroProvider has the following asynchronous functions, together with their equivalent callback methods:

Note, AgroProvider should be strongly referenced.


  • createPoly(poly: AgroPolygon, reponse: Binding<AgroPolyResponse>)
  • getPoly(id: String, reponse: Binding<AgroPolyResponse>)
  • getPolyList(reponse: Binding<[AgroPolyResponse]>)
  • deletePoly(id: String, reponse: Binding<AgroPolyResponse>)
  • updatePoly(id: String, name: String, reponse: Binding<AgroPolyResponse>)


  • getImagery(options: AgroOptions, reponse: Binding<[AgroImagery]>)
  • getStatsInfo(urlString: String, reponse: Binding<AgroStatsInfo>)
  • getTile(urlString: String, reponse: Binding<Data>)
  • getPngImageData(urlString: String, paletteid: Int, reponse: Binding<Data>)
  • getPngUIImage(urlString: String, paletteid: Int, reponse: Binding<UIImage>)
  • getGeoTiffData(urlString: String, paletteid: Int, reponse: Binding<Data>)
  • getGeoTiffUIImage(urlString: String, paletteid: Int, reponse: Binding<UIImage>)


  • getCurrentWeather(id: String, reponse: Binding<Current>)
  • getForecastWeather(id: String, reponse: Binding<[Current]>)
  • getHistoricalWeather(options: AgroWeatherOptions, reponse: Binding<[Current]>)

Historical NDVI

  • getHistoricalNDVI(options: AgroOptions, reponse: Binding<[AgroHistoryNDVI]>)


Include the files in the ./Sources/AgroApi folder into your project or preferably use Swift Package Manager.

Swift Package Manager (SPM)

Create a Package.swift file for your project and add a dependency to:

dependencies: [
  .package(url: "", from: "0.1.4")

Using Xcode

Select your project > Swift Packages > Add Package Dependency...

Then in your code:

import AgroApi



Requires a valid OpenWeather key, see:




  • Swift Tools 5.2.0


  • None
Last updated: Mon Sep 21 2020 13:54:26 GMT-0500 (GMT-05:00)