Cropland Data Layers V2 - Beta

Crop Land Data Layers, also known as CDLs, are published by USDA and provide estimates of historical crops cover.

Post Request Cropland Data Layers V2

Please note, you need to purchase a subscription key to call the API.
Please use the trial version to try now for a limited amount of uses before purchase.

Powered by CROPAI™

The Cropland Data Layer (CDL), produced by the USDA, provides a raster, geo-referenced, crop-specific land cover map for the continental United States. The CDL also includes a crop mask layer and planting frequency layers, as well as boundary, water and road layers. The Boundary Layer options provided are County, Agricultural Statistics Districts (ASD), State, and Region. The data is created annually using moderate resolution satellite imagery and extensive agricultural ground truth.

The purpose of the Cropland Data Layer Program is to use satellite imagery to (1) provide planted acreage estimates to the Agricultural Statistics Board for each state's major commodities and (2) produce digital, crop-specific, categorized geo-referenced output products (Information from here).


Cropland Data Layers in Ag-Analytics FarmScope.


Click the Jupyter Notebook Static Sample to view a static rendition of this APIs Jupyter Notebook.
Click the Jupyter Notebook Github Repo to access the Jupyter Notebook .ipynb files and
instructions needed in order to run this APIs Jupyter Notebook.

Request Parameters


Parameter Data Type Required? Default Options Description
file GeoTiff or Shapfile in Zip Yes
(otherwise pass aoi)
-- -- A GeoTiff(.TIFF,.Tif, .etc) or a Shapefile in Zip
(must include shp, shx, dbf, but others files such as .prj, .xml, .cpg
are recommended for better processing)
aoi GeoJSON String,
.shp file, GeoTIFF
Yes
(otherwise pass file)
-- -- Area of interest to return.
Projection String No See Request
Handling Table
EPSG code
("EPSG:4326") WKT
Output projection of result GeoTIFF.
Resolution Float No See Request
Handling Table
-- Output resolution of result GeoTIFF.
years List of integers as String Yes -- "['2015','2016']" Call will return CDL GeoTiffs from the given years.
product List of string as String No 'CDL' "['CultivatedLayer','CDL']" Get 'CultivatedLayer','CDL', or both in the response

Request Handling - Default Projections and Resolutions


AOI Type Projection
Specified?
Resolution
Specified?
Ouput Projection Output Resolution
Any Yes Yes Request projection Request resolution
GeoTIFF Yes No Request projection GeoTIFF resolution
GeoTIFF No Yes GeoTIFF projection Request resolution
GeoTIFF No No GeoTIFF projection GeoTIFF resolution
Shapefile Yes No Request projection Native tile resolution
Shapefile No Yes Shapefile projection Request resolution
Shapefile No No Shapefile projection Native tile resolution
GeoJSON Yes No Request projection Native tile resolution
GeoJSON No Yes GeoJSON projection Request resolution
GeoJSON No No GeoJSON projection Native tile resolution

Response Parameters


Parameter Data Type Description
year Key Request year of CDL layer
file String Result raster name. Can be used as request parameter for GET request
attributes.
extent
-- Extents of the result raster. Specifies the bottom left and top right corners of the field raster in degrees.
attributes.
pngb64
Link Base64png image of the result raster with legend entries.
attributes.
legend
List Legend gives the following details for each range of values:
     1. color: Hex color used for the crop type
     2. Area: Area of certain crop(see CropCode) covered in percentage
     3. Count: Number of pixels from the result raster of certain crop(see Value)
     4. CountAllPixels: Total number of pixels in the result raster
     5. CropCode: CDL code, ex: CDL code for corn is 1
     6. CropName: Crop name based on NASS in string
     7. Acres: Area of the crop in acres



Call API

Request

Request URL

Request headers

  • (optional)
    string
  • string

Request body

years=%5B%272015%27%5D&aoi=%7B%22type%22%3A%22Feature%22%2C%22geometry%22%3A%7B%22type%22%3A%22MultiPolygon%22%2C%22coordinates%22%3A%5B%5B%5B%5B-90.61615826299999%2C34.88433474400006%5D%2C%5B-90.62275980699997%2C34.884609527000066%5D%2C%5B-90.62274692099999%2C34.88210716700007%5D%2C%5B-90.62293616799997%2C34.877367339000045%5D%2C%5B-90.62594201999997%2C34.87357967200006%5D%2C%5B-90.62725009699994%2C34.87208965600007%5D%2C%5B-90.62716756099996%2C34.87090527500004%5D%2C%5B-90.62539963699999%2C34.872279167000045%5D%2C%5B-90.62444578899994%2C34.873204163000025%5D%2C%5B-90.62219769799998%2C34.87732304900004%5D%2C%5B-90.61977458099994%2C34.880634050000026%5D%2C%5B-90.61820201599994%2C34.88053865000006%5D%2C%5B-90.61615826299999%2C34.88433474400006%5D%5D%5D%2C%5B%5B%5B-90.63119889699999%2C34.867975186000024%5D%2C%5B-90.63014481999994%2C34.86857839900006%5D%2C%5B-90.62947153999994%2C34.869106147000025%5D%2C%5B-90.62809533699999%2C34.87019944200006%5D%2C%5B-90.62923145399998%2C34.870240986000056%5D%2C%5B-90.63149278299994%2C34.868794869000055%5D%2C%5B-90.63330843399996%2C34.867806087000076%5D%2C%5B-90.63286253399997%2C34.86716888700005%5D%2C%5B-90.63119889699999%2C34.867975186000024%5D%5D%5D%2C%5B%5B%5B-90.62522472499995%2C34.87741208600005%5D%2C%5B-90.62701314399999%2C34.877440954000065%5D%2C%5B-90.62706890399994%2C34.87537116300007%5D%2C%5B-90.62522472499995%2C34.87741208600005%5D%5D%5D%5D%7D%7D&product=%5B%27CultivatedLayer%27%2C%27CDL%27%5D

Responses

200 OK

Code samples

@ECHO OFF

curl -v -X POST "https://ag-analytics.azure-api.net/cdl-range-read/"
-H "Content-Type: application/x-www-form-urlencoded"
-H "Ocp-Apim-Subscription-Key: {subscription key}"

--data-ascii "{body}" 
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }
        
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");

            var uri = "https://ag-analytics.azure-api.net/cdl-range-read/?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}	
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://ag-analytics.azure-api.net/cdl-range-read/");


            URI uri = builder.build();
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "application/x-www-form-urlencoded");
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");


            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
    $(function() {
        var params = {
            // Request parameters
        };
      
        $.ajax({
            url: "https://ag-analytics.azure-api.net/cdl-range-read/?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSString* path = @"https://ag-analytics.azure-api.net/cdl-range-read/";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"POST"];
    // Request headers
    [_request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [_request setValue:@"{subscription key}" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
    // Request body
    [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];

    if (nil != error)
    {
        NSLog(@"Error: %@", error);
    }
    else
    {
        NSError* error = nil;
        NSMutableDictionary* json = nil;
        NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", dataString);
        
        if (nil != _connectionData)
        {
            json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
        }
        
        if (error || !json)
        {
            NSLog(@"Could not parse loaded json with error:%@", error);
        }
        
        NSLog(@"%@", json);
        _connectionData = nil;
    }
    
    [pool drain];

    return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://ag-analytics.azure-api.net/cdl-range-read/');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/x-www-form-urlencoded',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.urlencode({
})

try:
    conn = httplib.HTTPSConnection('ag-analytics.azure-api.net')
    conn.request("POST", "/cdl-range-read/?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/x-www-form-urlencoded',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
})

try:
    conn = http.client.HTTPSConnection('ag-analytics.azure-api.net')
    conn.request("POST", "/cdl-range-read/?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
require 'net/http'

uri = URI('https://ag-analytics.azure-api.net/cdl-range-read/')


request = Net::HTTP::Post.new(uri.request_uri)
# Request headers
request['Content-Type'] = 'application/x-www-form-urlencoded'
# Request headers
request['Ocp-Apim-Subscription-Key'] = '{subscription key}'
# Request body
request.body = "{body}"

response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
end

puts response.body