Ag-Analytics® - SSURGO Soils API

The Soil Survey Geographic Database (SSURGO) Soils API provides soil type and soil type attribute averages (e.g., NCCPI) by field for a shape entered. This API uses POST and GET request with a subscription key. Soil Type data is derived from NRCS USDA; average soil type attribute data are available for processing for the continental USA. It uses data provided by the USDA NRCS, which can be downloaded from http://sdmdataaccess.nrcs.usda.gov. Those soil type attributes contain both numerical data type and categorical (ordinal) data type, which can be found from the links in the reference.

Post Request Parameters

1). AOI (GeoJSON String): Area of interest as Geojson string containing boundary coordinates. file(GeoTiff or Shapfile in Zip): Alternative AOI format when GeoJSON is not available. 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)

2).Projection(String):Output projection of result GeoTIFF.Provided as EPSG code, ex: "EPSG:4326"

3).Resolution(Float):Output resolution of result GeoTIFF.

4).Soil_Parameter(String): The soil metric to return, see the NRCS variables PDF for full list with descriptions

Library

In [1]:
import requests
import json
import os
from collections import defaultdict
import pandas as pd
from IPython.display import Image

%matplotlib inline
%autosave 0
Autosave disabled

POST Request API Fuction

In [25]:
def ssurgo_service(values, files, headers):
    try:
        url = 'https://ag-analytics.azure-api.net/ssurgo-v2'
        
        if files == None:
            response = requests.post(url, data=values,headers = headers).json()
        else:
            response = requests.post(url, files = files, data = values,headers = headers).json()
            
        print(response)
        
        return response
    
    except Exception as e:
        print(e)
        raise e

1. GeoJSON as AOI

In [29]:
#Parameters to call SSURGO API
values = {'AOI': '{"geometryType": "esriGeometryPolygon", "features": [{"geometry": {"rings": [[[-85.179, 42.74], [-85.17858886748223, 42.74188232450973], [-85.17858886748223, 42.742675781062474], [-85.1782836915391, 42.742675781062474], [-85.1782226563505, 42.74230956993074], [-85.17529296909521, 42.74230956993074], [-85.17529296909521, 42.74353027370324], [-85.17529296909521, 42.74371337926908], [-85.17492675796348, 42.74389648393566], [-85.17437744126585, 42.744079589501496], [-85.17340087914721, 42.744079589501496], [-85.17327880876996, 42.74749755826576], [-85.17401123013411, 42.74749755826576], [-85.17401123013411, 42.74847412128372], [-85.17529296909521, 42.74847412128372], [-85.17590332008211, 42.74829101571788], [-85.17749023408697, 42.74792480458609], [-85.17761230446422, 42.7470703128447], [-85.1782836915391, 42.746704101712965], [-85.18072509728535, 42.746704101712965], [-85.179, 42.74]]], "spatialReference": {"wkid": 4326}}}]}', 
'Soil_Parameter': 'nccpi2all',
'Projection': 'EPSG:4326', 
'Resolution': 0.00001,
'Product':'GeoJSON'}
file = None

# Basic Header Pattern.
# headers=None
# Header for using a subscription key.
# headers={'Content-Type':'application/x-www-form-urlencoded','Ocp-Apim-Subscription-Key': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

Call SSURGO API

In [31]:
SSURGO_response_GeoJSON = ssurgo_service(values, file, headers)
{'attributes': {'GeoJSON': {'crs': {'properties': {'name': 'urn:ogc:def:crs:OGC:1.3:CRS84'}, 'type': 'name'}, 'features': [{'geometry': {'coordinates': [[[-85.17364994099194, 42.74739381697111], [-85.17377913220116, 42.74742650822685], [-85.17387346748649, 42.747493420485], [-85.17387584382337, 42.74749755861743], [-85.17348729857176, 42.74749755874103], [-85.1734504165035, 42.747386498288336], [-85.17364994099194, 42.74739381697111]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Udorthents and Udipsamments, 0 to 6 percent slopes', 'area': 311.26838986575603, 'mukey': 186064.0, 'nccpi2all': 0.0, 'w_nccpi2al': 0.0}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[-85.179, 42.74], [-85.17910007727738, 42.740388962302006], [-85.17892976287567, 42.74032158106214], [-85.179, 42.74]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Glendora loamy fine sand', 'area': 270.62486958503723, 'mukey': 186065.0, 'nccpi2all': 0.123, 'w_nccpi2al': 33.28685895895958}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[-85.17945218239498, 42.74175742145311], [-85.18072509728535, 42.746704101712965], [-85.17938074908345, 42.74670410812824], [-85.17929287656494, 42.74654444956673], [-85.17923579479606, 42.746274696120395], [-85.17921896398394, 42.74593863565957], [-85.17918891493645, 42.74583577659985], [-85.17900896958821, 42.74554145547387], [-85.1789132547429, 42.74546814633794], [-85.17882411753897, 42.74543720696158], [-85.17874106245006, 42.74543879966092], [-85.17865964142925, 42.74546233851618], [-85.17858237797435, 42.74552009477662], [-85.1785388984514, 42.745581561639824], [-85.17847987864343, 42.74573628729985], [-85.1784032680963, 42.746181548839445], [-85.17832773133966, 42.74633045858383], [-85.17820006897796, 42.74644057607179], [-85.17790777582314, 42.74662856495638], [-85.17768561809675, 42.74687406188849], [-85.17759996306779, 42.747085245187975], [-85.17756728170463, 42.747349000156305], [-85.17752149991725, 42.74753303741977], [-85.17746138473507, 42.74763908727414], [-85.17737654089461, 42.74773773390933], [-85.17727701562171, 42.74781197654153], [-85.17717648400748, 42.747851892950564], [-85.17706046786628, 42.747870837169444], [-85.17670923494319, 42.747887132884955], [-85.17609144926092, 42.74806465635885], [-85.17561397220703, 42.748285673744874], [-85.17543041608081, 42.74842161076879], [-85.1754143648407, 42.74843770285073], [-85.17529296909521, 42.74847412128372], [-85.17401123013411, 42.74847412128372], [-85.17401123013411, 42.74749755826576], [-85.17387584382337, 42.74749755861743], [-85.17387346748649, 42.747493420485], [-85.17377913220116, 42.74742650822685], [-85.17364994099194, 42.74739381697111], [-85.1734504165035, 42.747386498288336], [-85.17327912900022, 42.74748859231621], [-85.17339311782554, 42.744296917615124], [-85.17370538779335, 42.74411269984125], [-85.17400246893874, 42.74410181894382], [-85.1741107899248, 42.74407959032487], [-85.17437744126585, 42.744079589501496], [-85.17492675796348, 42.74389648393566], [-85.17529296909521, 42.74371337926908], [-85.17529296909521, 42.74353027370324], [-85.17529296909527, 42.74327860985535], [-85.17530961015035, 42.74324871215839], [-85.1753174396481, 42.743175373344855], [-85.17529296909524, 42.7431103856446], [-85.17529296909517, 42.74265810932693], [-85.17529659696032, 42.742650838365535], [-85.17537865560041, 42.74236969050884], [-85.17542414781872, 42.74230957152762], [-85.17699836790574, 42.74230957901257], [-85.1770104745537, 42.74231063113075], [-85.17701729052503, 42.74230957897141], [-85.17818496615072, 42.74230957040468], [-85.1781845619679, 42.7423149325881], [-85.17823173680517, 42.742455216934786], [-85.17824957710923, 42.742471095020996], [-85.1782836915391, 42.742675781062474], [-85.17858886748223, 42.742675781062474], [-85.17858886748215, 42.7424956459303], [-85.17863878705032, 42.7424523903656], [-85.1787835257391, 42.742175880312686], [-85.17892012916059, 42.74203875798236], [-85.17920648858853, 42.74185461100154], [-85.17943633461908, 42.741759474420235], [-85.17945218239498, 42.74175742145311]], [[-85.1769630200273, 42.74259772350621], [-85.17687189622097, 42.74268663408094], [-85.17675515882348, 42.74291338644366], [-85.17663845649952, 42.74305537770357], [-85.17648720671917, 42.74316757802137], [-85.176134069032, 42.743331144017134], [-85.1760800944208, 42.743381854089364], [-85.17603506536591, 42.74346049710431], [-85.17601532704566, 42.74358097208426], [-85.17604287507856, 42.74393729606942], [-85.1759675388708, 42.744294778381345], [-85.17588847946973, 42.7444182714861], [-85.17562949540485, 42.74462461643293], [-85.17557714137195, 42.74470304001335], [-85.17556643224503, 42.744752866051954], [-85.17565652542828, 42.745291968249774], [-85.17574494857047, 42.745391764218596], [-85.17589971200209, 42.74545696326828], [-85.17603734155006, 42.745459661234406], [-85.17620648154383, 42.74539905951906], [-85.1764866932063, 42.74510407469336], [-85.17674715036065, 42.74487531864111], [-85.17707699380816, 42.7443968343465], [-85.17742754054854, 42.744057327683606], [-85.17759945135356, 42.743779957878814], [-85.17761972387115, 42.74367973832932], [-85.17761133229709, 42.743597938693995], [-85.17742647485187, 42.743182026529325], [-85.177339803589, 42.7428604838243], [-85.17725418003636, 42.74273844582268], [-85.17716747549855, 42.74265743309411], [-85.17707460610814, 42.74261235097924], [-85.1769630200273, 42.74259772350621]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Houghton muck, 0 to 1 percent slopes', 'area': 258170.8505424559, 'mukey': 186072.0, 'nccpi2all': 0.071, 'w_nccpi2al': 18330.130388514368}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[[-85.1769630200273, 42.74259772350621], [-85.17707460610814, 42.74261235097924], [-85.17716747549855, 42.74265743309411], [-85.17725418003636, 42.74273844582268], [-85.177339803589, 42.7428604838243], [-85.17742647485187, 42.743182026529325], [-85.17761133229709, 42.743597938693995], [-85.17761972387115, 42.74367973832932], [-85.17759945135356, 42.743779957878814], [-85.17742754054854, 42.744057327683606], [-85.17707699380816, 42.7443968343465], [-85.17674715036065, 42.74487531864111], [-85.1764866932063, 42.74510407469336], [-85.17620648154383, 42.74539905951906], [-85.17603734155006, 42.745459661234406], [-85.17589971200209, 42.74545696326828], [-85.17574494857047, 42.745391764218596], [-85.17565652542828, 42.745291968249774], [-85.17556643224503, 42.744752866051954], [-85.17557714137195, 42.74470304001335], [-85.17562949540485, 42.74462461643293], [-85.17588847946973, 42.7444182714861], [-85.1759675388708, 42.744294778381345], [-85.17604287507856, 42.74393729606942], [-85.17601532704566, 42.74358097208426], [-85.17603506536591, 42.74346049710431], [-85.1760800944208, 42.743381854089364], [-85.176134069032, 42.743331144017134], [-85.17648720671917, 42.74316757802137], [-85.17663845649952, 42.74305537770357], [-85.17675515882348, 42.74291338644366], [-85.17687189622097, 42.74268663408094], [-85.1769630200273, 42.74259772350621]]], [[[-85.1741107899248, 42.74407959032487], [-85.17400246893874, 42.74410181894382], [-85.17370538779335, 42.74411269984125], [-85.17366319799812, 42.744079590316325], [-85.1741107899248, 42.74407959032487]]], [[[-85.17529296909524, 42.7431103856446], [-85.1753174396481, 42.743175373344855], [-85.17530961015035, 42.74324871215839], [-85.17529296909527, 42.74327860985535], [-85.17529296909524, 42.7431103856446]]]], 'type': 'MultiPolygon'}, 'properties': {'Soil_Type': 'Filer loam, 6 to 12 percent slopes', 'area': 28145.973178192973, 'mukey': 186079.0, 'nccpi2all': 0.57800001, 'w_nccpi2al': 16268.37277845527}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[-85.17882411753897, 42.74543720696158], [-85.1789132547429, 42.74546814633794], [-85.17900896958821, 42.74554145547387], [-85.17918891493645, 42.74583577659985], [-85.17921896398394, 42.74593863565957], [-85.17923579479606, 42.746274696120395], [-85.17929287656494, 42.74654444956673], [-85.17938074908345, 42.74670410812824], [-85.1782836915391, 42.746704101712965], [-85.17761230446422, 42.7470703128447], [-85.17749023408697, 42.74792480458609], [-85.17590332008211, 42.74829101571788], [-85.1754143648407, 42.74843770285073], [-85.17543041608081, 42.74842161076879], [-85.17561397220703, 42.748285673744874], [-85.17609144926092, 42.74806465635885], [-85.17670923494319, 42.747887132884955], [-85.17706046786628, 42.747870837169444], [-85.17717648400748, 42.747851892950564], [-85.17727701562171, 42.74781197654153], [-85.17737654089461, 42.74773773390933], [-85.17746138473507, 42.74763908727414], [-85.17752149991725, 42.74753303741977], [-85.17756728170463, 42.747349000156305], [-85.17759996306779, 42.747085245187975], [-85.17768561809675, 42.74687406188849], [-85.17790777582314, 42.74662856495638], [-85.17820006897796, 42.74644057607179], [-85.17832773133966, 42.74633045858383], [-85.1784032680963, 42.746181548839445], [-85.17847987864343, 42.74573628729985], [-85.1785388984514, 42.745581561639824], [-85.17858237797435, 42.74552009477662], [-85.17865964142925, 42.74546233851618], [-85.17874106245006, 42.74543879966092], [-85.17882411753897, 42.74543720696158]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Filer loam, 12 to 18 percent slopes', 'area': 13771.85596176982, 'mukey': 186080.0, 'nccpi2all': 0.542, 'w_nccpi2al': 7464.345931279243}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[-85.17366319799812, 42.744079590316325], [-85.17370538779335, 42.74411269984125], [-85.17339311782554, 42.744296917615124], [-85.17340087914721, 42.744079589501496], [-85.17366319799812, 42.744079590316325]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Oshtemo sandy loam, 6 to 12 percent slopes', 'area': 341.6368469148874, 'mukey': 186088.0, 'nccpi2all': 0.59200001, 'w_nccpi2al': 202.24901678998182}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[[-85.17892976287567, 42.74032158106214], [-85.17910007727738, 42.740388962302006], [-85.17945218239498, 42.74175742145311], [-85.17943633461908, 42.741759474420235], [-85.17920648858853, 42.74185461100154], [-85.17892012916059, 42.74203875798236], [-85.1787835257391, 42.742175880312686], [-85.17863878705032, 42.7424523903656], [-85.17858886748215, 42.7424956459303], [-85.17858886748223, 42.74188232450973], [-85.17892976287567, 42.74032158106214]]], [[[-85.1782226563505, 42.74230956993074], [-85.17824957710923, 42.742471095020996], [-85.17823173680517, 42.742455216934786], [-85.1781845619679, 42.7423149325881], [-85.17818496615072, 42.74230957040468], [-85.1782226563505, 42.74230956993074]]]], 'type': 'MultiPolygon'}, 'properties': {'Soil_Type': 'Spinks loamy sand, 0 to 6 percent slopes', 'area': 8523.60479144752, 'mukey': 186096.0, 'nccpi2all': 0.48899999, 'w_nccpi2al': 4168.04265778179}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[[-85.17701729052503, 42.74230957897141], [-85.1770104745537, 42.74231063113075], [-85.17699836790574, 42.74230957901257], [-85.17701729052503, 42.74230957897141]]], [[[-85.17542414781872, 42.74230957152762], [-85.17537865560041, 42.74236969050884], [-85.17529659696032, 42.742650838365535], [-85.17529296909517, 42.74265810932693], [-85.17529296909521, 42.74230956993074], [-85.17542414781872, 42.74230957152762]]]], 'type': 'MultiPolygon'}, 'properties': {'Soil_Type': 'Marlette fine sandy loam, 2 to 6 percent slopes', 'area': 173.7088620158611, 'mukey': 186103.0, 'nccpi2all': 0.58600003, 'w_nccpi2al': 101.79339835256046}, 'type': 'Feature'}, {'geometry': {'coordinates': [[[-85.1734504165035, 42.747386498288336], [-85.17348729857176, 42.74749755874103], [-85.17327880876996, 42.74749755826576], [-85.17327912900022, 42.74748859231621], [-85.1734504165035, 42.747386498288336]]], 'type': 'Polygon'}, 'properties': {'Soil_Type': 'Boyer loamy sand, 12 to 18 percent slopes', 'area': 112.13497176766396, 'mukey': 186130.0, 'nccpi2all': 0.40400001, 'w_nccpi2al': 45.30252971548596}, 'type': 'Feature'}], 'name': 'SSURGOshapefile_dissolved_nccpi2all_20200717160419718335', 'type': 'FeatureCollection'}, 'Soil_Parameter': 'nccpi2all', 'Weighted_Average': 0.15045275981822384}}

2. Raster (.tif) as AOI

In [43]:
#Path to raster in your local machine
# rasterpath = r"raster path on your local machine"
rasterpath = r"C:\Users\Xuewei\Documents\Xueweilocal\test_raster\test_raster.tif"
files = [('file',(open(rasterpath, 'rb')))]
values = {'Soil_Parameter': 'nccpi2all',
'Projection': 'EPSG:4326', 
'Resolution': 0.0001,
'Product':'raster'}
headers={'Ocp-Apim-Subscription-Key': "XXXXXXXXXXXXXXXXXXXXXXXXXX"}

Call SSURGO API

In [44]:
SSURGO_response_raster = ssurgo_service(values, files, headers)
{'attributes': {'CellSize': [0.0001, -0.0001], 'CoordinateSystem': 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]', 'Extent': '-90.60760921213281, 39.10684154247035, -90.59080921213281, 39.12204154247035', 'Legend': [{'Acres': 93006.0046249134, 'Area': '8.8 %', 'Count': 906, 'CountAllPixels': 10296, 'Soil_Type': 'Water', 'Soil_Value': 0.0, 'Value': 175536.0, 'color': '#5ec68d'}, {'Acres': 65024.39249074459, 'Area': '6.45 %', 'Count': 664, 'CountAllPixels': 10296, 'Soil_Type': 'Water', 'Soil_Value': 0.0, 'Value': 211794.0, 'color': '#304a33'}, {'Acres': 63124.534493334744, 'Area': '6.01 %', 'Count': 619, 'CountAllPixels': 10296, 'Soil_Type': 'Water', 'Soil_Value': 0.0, 'Value': 728317.0, 'color': '#0a7fad'}, {'Acres': 274435.64372268086, 'Area': '26.86 %', 'Count': 2765, 'CountAllPixels': 10296, 'Soil_Type': 'Tice silty clay loam, 0 to 2 percent slopes, occasionally flooded', 'Soil_Value': 0.83700001, 'Value': 728434.0, 'color': '#cfcfdc'}, {'Acres': 208908.0189410051, 'Area': '23.37 %', 'Count': 2406, 'CountAllPixels': 10296, 'Soil_Type': 'Beaucoup silty clay loam, cool mesic, 0 to 2 percent slopes, occasionally flooded', 'Soil_Value': 0.91799998, 'Value': 728461.0, 'color': '#70f675'}, {'Acres': 28523.76436123107, 'Area': '3.9 %', 'Count': 402, 'CountAllPixels': 10296, 'Soil_Type': 'Quiver silty clay loam, 0 to 2 percent slopes, frequently flooded, long duration', 'Soil_Value': 0.226, 'Value': 728463.0, 'color': '#2c82e3'}, {'Acres': 89701.56500762027, 'Area': '10.74 %', 'Count': 1106, 'CountAllPixels': 10296, 'Soil_Type': 'McFain silty clay, 0 to 2 percent slopes, occasionally flooded', 'Soil_Value': 0.70499998, 'Value': 728483.0, 'color': '#5bf688'}, {'Acres': 105495.71719076799, 'Area': '11.26 %', 'Count': 1159, 'CountAllPixels': 10296, 'Soil_Type': 'Beaucoup silty clay loam, undrained, 0 to 2 percent slopes, frequently flooded, long duration', 'Soil_Value': 0.092, 'Value': 2542043.0, 'color': '#7b49da'}, {'Acres': 15505.643569231033, 'Area': '2.0 %', 'Count': 206, 'CountAllPixels': 10296, 'Soil_Type': 'Quiver silty clay loam, 0 to 2 percent slopes, frequently flooded, long duration', 'Soil_Value': 0.226, 'Value': 2542279.0, 'color': '#79c1f8'}, {'Acres': 3643.723698735237, 'Area': '0.61 %', 'Count': 63, 'CountAllPixels': 10296, 'Soil_Type': 'Beaucoup silty clay loam, cool mesic, 0 to 2 percent slopes, occasionally flooded', 'Soil_Value': 0.91799998, 'Value': 2542292.0, 'color': '#6623a6'}], 'Soil_Parameter': 'nccpi2all', 'Weighted_Average': 0.535927375079309, 'pngb64': 'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAKgAAACYCAYAAABwMaIZAAAITElEQVR4nO2dPWhWVxjHH6vTu8o7BoqVZh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ofbZI8RNVD0AzQeYYSl6TjovqWFBXPQKynzzXRJYzP8WTf2iYqHhBRt/g+t0JdTix1gQRlwHbC5HtnqC1Nfc/Mm9LUNkFxHpSB+i6T9FNPRG+T1KekKk05Diyj4iPie4IRq+4Vi5OPnKsfgmZObEmJ3ManGIN6RKfuQz2EK9bsXmH7vngkaGRC7WtLSFIbIGhBxH4hgg2o+ED01X2OVW9b63WQoIWRWtVDUCGEPGOZUtWj4iPg6xlOpvjeaULFAyfafhmGtC2m7iGoMCQ9fUSCpKh4QdSrX0LVKzjfHGcKElQokiZNMSsfggpmauro0NcLvsbRvXUktKg4bicIKQ+H6ENJGmIPHwkqnPmdi5WE/fomQqQpBBWOStVQdW8j6ZC2ex/lbQtm8YkR4n1Lpontc2iCBAX7kLQVCkGBaFDxCeO77nWrHhUPigWCAtGg4jPBV93r1DwqHhQLBAWdxF5ywl58JtR3mUIs5ocCCQp6iZmiEDQzQqen7xNYmMVnDqew9Rl9qKOBSFAgGggKtIkxFsUsPnNSn91jDFoQnIKGulcKFQ9EgwQtFNc0RYICQBAUCAcVD7TrPlSt10GCAtFA0MKRvjaKigd7GBc2Rq3XQYIC0UBQIJr/ARFZMh90SbW0AAAAAElFTkSuQmCC'}, 'filename': 'result_ssurgo_raster_proj_4326_res_0.0001_20200717171310522516.tif'}

Visualize the response

1. GeoJSON's product

In [37]:
# import required library

import folium
import mplleaflet
In [38]:
#Display result GeoJSON on map
result_geojson = SSURGO_response_GeoJSON['attributes']['GeoJSON']
zoom_point=result_geojson['features'][0]['geometry']['coordinates'][0][0]
zoom_point
m = folium.Map([zoom_point[1],zoom_point[0]],tiles='Cartodb Positron', zoom_start=11,width='70%', height='100%')
for shape in result_geojson['features']:
    folium.GeoJson(shape).add_to(m)
m
Out[38]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [41]:
result_geojson = SSURGO_response_GeoJSON['attributes']['GeoJSON']
zoom_point=result_geojson['features'][0]['geometry']['coordinates'][0][0]
zoom_point
m = folium.Map([zoom_point[1],zoom_point[0]],tiles='Cartodb Positron', zoom_start=11,width='70%', height='100%')
for shape in result_geojson['features']:
    m.add_child(folium.GeoJson(data=shape).add_child(folium.Popup(str(shape["properties"]))))
m
Out[41]:
Make this Notebook Trusted to load map: File -> Trust Notebook

2. Raster's product

In [34]:
# pngb64
attributes =SSURGO_response_raster['attributes']
pngb64 = attributes['pngb64']
In [35]:
#Image Legend
df=defaultdict(list)

Legend = attributes['Legend']
    
for val in Legend:
    df['Acres'].append(float(val['Acres']))
    df['Area'].append(val['Area'])
    df['Value'].append(val['Value'])
    df['Soil_Type'].append(val['Soil_Type'])
    df['color'].append(val['color'])

    
legenddf = pd.DataFrame.from_dict(df)    
legenddf.style.applymap(lambda x:"background-color: %s"%x, subset=['color'])
Out[35]:
Acres Area Value Soil_Type color
0 93006 8.8 % 175536 Water #05940c
1 65024.4 6.45 % 211794 Water #665298
2 63124.5 6.01 % 728317 Water #5533c1
3 274436 26.86 % 728434 Tice silty clay loam, 0 to 2 percent slopes, occasionally flooded #be0ea9
4 208908 23.37 % 728461 Beaucoup silty clay loam, cool mesic, 0 to 2 percent slopes, occasionally flooded #5a5176
5 28523.8 3.9 % 728463 Quiver silty clay loam, 0 to 2 percent slopes, frequently flooded, long duration #c8b5f4
6 89701.6 10.74 % 728483 McFain silty clay, 0 to 2 percent slopes, occasionally flooded #10f28a
7 105496 11.26 % 2.54204e+06 Beaucoup silty clay loam, undrained, 0 to 2 percent slopes, frequently flooded, long duration #1a6557
8 15505.6 2.0 % 2.54228e+06 Quiver silty clay loam, 0 to 2 percent slopes, frequently flooded, long duration #018111
9 3643.72 0.61 % 2.54229e+06 Beaucoup silty clay loam, cool mesic, 0 to 2 percent slopes, occasionally flooded #aca535
In [36]:
# Visualize CDL
Image(url = pngb64, width = 400, height = 400)
Out[36]:

GET Request

In [46]:
# Specify local path where file will be downloaded.
# local_path = r"C:\<Path to download directory>" # E.g., r"C:\Users\John_Doe\Documents\rasters"
local_path = r'C:'
# Create GET request payload.
values = {'filename': SSURGO_response_raster['filename']}
print(values)
{'filename': 'result_ssurgo_raster_proj_4326_res_0.0001_20200717171310522516.tif'}
In [50]:
# Get SSURGO file 
def SSURGO_get(values, local_path,headers):
    try:
        url = 'https://ag-analytics.azure-api.net/ssurgo-v2'
    
        download_path = os.path.join(local_path, values['filename'])
        print(values)
     
        response = requests.get(url, params=values,headers=headers)
        open(download_path, 'wb').write(response.content)
        
        print(response.url)

        return response
    
    except Exception as e:
        print(e)
        raise e
In [51]:
SSURGO_get(values, local_path,headers)
{'filename': 'result_ssurgo_raster_proj_4326_res_0.0001_20200717171310522516.tif'}
https://ag-analytics.azure-api.net/ssurgo-v2?filename=result_ssurgo_raster_proj_4326_res_0.0001_20200717171310522516.tif
Out[51]:
<Response [200]>
In [ ]: