Ag Analytics-PolarisSoilsDataLayers-Demo

The POLARIS Soils Data Layers API provides a spatially continuous, internally consistent, quantitative prediction of soil series at a 30 m spatial resolution for the contiguous United States.
In [ ]:
import requests
import json
import time
from pandas.io.json import json_normalize
from collections import defaultdict
import pandas as pd
import geopandas as gpd
import requests, zipfile, io
%matplotlib inline
%autosave 0

API Details:

Request URL: https://ag-analytics.azure-api.net/PolarisSoilsDataLayers/get[?inputShape][&SoilValue][&Statistics][&SoilHorizon]

Parameters:

inputShape - The shape information for field in esriGeometryPolygon format.

SoilValue - e.g. pH, Organic Matter

Statistics - Statistics options are: min, max, mean, and variance

SoilHorizon - Soil depth in CM.

In order to get Ocp-Apim-Subscription-Key, please click on this link https://analytics.ag/Session/SignInToAPIPayment

Request Parameters

In [ ]:
inputShape={"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-89.045774,43.730605],[-89.04577,43.730488],[-89.045722,43.729998],[-89.045789,43.729653],[-89.045661,43.72961],[-89.045635,43.729782],[-89.045644,43.730045],[-89.045653,43.730308],[-89.045651,43.730607],[-89.041228,43.730676],[-89.041171,43.728908],[-89.041111,43.727076],[-89.042892,43.727044],[-89.044665,43.727018],[-89.046178,43.726999],[-89.046237,43.730597],[-89.045774,43.730605]]],"spatialReference":{"wkid":4326}}}]}
SoilValue="ph"
Statistics="mean"
SoilHorizon="0_5"
headers={'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
           

API Function

In [4]:
def get_polarissoil_datalayers(inputShape,SoilValue,Statistics,SoilHorizon,headers):
    try:
        url = "https://ag-analytics.azure-api.net/PolarisSoilsDataLayers/get?inputShape={}&SoilValue={}&Statistics={}&SoilHorizon={}".format(inputShape,SoilValue,Statistics,SoilHorizon)
     
        response = (requests.get(url,headers=headers).text)
        
        response_json = json.loads(response)
        print(response_json)
        time.sleep(0.5)
        return response_json
    
    except Exception as e:
        raise e

Calling API Function and Displaying Response

In [5]:
polaris=get_polarissoil_datalayers(inputShape,SoilValue,Statistics,SoilHorizon,headers)
{'results': [{'paramName': 'MeanFieldValue', 'dataType': 'GPString', 'value': '6.17'}, {'paramName': 'PolygonOutput', 'dataType': 'GPFeatureRecordSetLayer', 'value': {'displayFieldName': '', 'geometryType': 'esriGeometryPolygon', 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}, 'fields': [{'name': 'FID', 'type': 'esriFieldTypeOID', 'alias': 'FID'}, {'name': 'ID', 'type': 'esriFieldTypeInteger', 'alias': 'ID'}, {'name': 'GRIDCODE', 'type': 'esriFieldTypeInteger', 'alias': 'GRIDCODE'}, {'name': 'val_float', 'type': 'esriFieldTypeDouble', 'alias': 'val_float'}, {'name': 'Shape_Length', 'type': 'esriFieldTypeDouble', 'alias': 'Shape_Length'}, {'name': 'Shape_Area', 'type': 'esriFieldTypeDouble', 'alias': 'Shape_Area'}], 'features': [{'attributes': {'FID': 1, 'ID': 1, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.0025317420608140925, 'Shape_Area': 2.097253454345347e-07}, 'geometry': {'rings': [[[-88.51322198999998, 39.598409325000034], [-88.51421776299998, 39.598469014000045], [-88.51420851599994, 39.59855797100005], [-88.51414994099997, 39.59855446000006], [-88.51414531799998, 39.598598938000066], [-88.51408674299995, 39.59859542700008], [-88.51408211899997, 39.59863990600007], [-88.51396496899997, 39.59863288400004], [-88.51396034499999, 39.598677363000036], [-88.51331601999999, 39.59863874000007], [-88.51331139599995, 39.598683219000065], [-88.51319424599996, 39.59867619600004], [-88.51322198999998, 39.598409325000034]]]}}, {'attributes': {'FID': 2, 'ID': 2, 'GRIDCODE': 6209930, 'val_float': 6.20993, 'Shape_Length': 0.0028558977982848887, 'Shape_Area': 3.1983131838778713e-07}, 'geometry': {'rings': [[[-88.51210906999995, 39.59834260500003], [-88.51322198999998, 39.598409325000034], [-88.51319424599996, 39.59867619600004], [-88.51254991999997, 39.59863757000005], [-88.51254529599998, 39.59868204800006], [-88.51207669599995, 39.59865395500003], [-88.51210906999995, 39.59834260500003]]]}}, {'attributes': {'FID': 3, 'ID': 3, 'GRIDCODE': 6133198, 'val_float': 6.133198, 'Shape_Length': 0.0028279723898758553, 'Shape_Area': 3.6177576394967585e-07}, 'geometry': {'rings': [[[-88.51105472599994, 39.59827938800004], [-88.51210906999995, 39.59834260500003], [-88.51207669599995, 39.59865395500003], [-88.51172524599997, 39.59863288300005], [-88.51172062099994, 39.59867736100006], [-88.51101772199996, 39.59863521500006], [-88.51105472599994, 39.59827938800004]]]}}, {'attributes': {'FID': 4, 'ID': 4, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.0031242047257856857, 'Shape_Area': 4.561515116667375e-07}, 'geometry': {'rings': [[[-88.50994180899994, 39.59821264900006], [-88.51105472599994, 39.59827938800004], [-88.51101772199996, 39.59863521500006], [-88.51095914699994, 39.59863170300008], [-88.51095452099997, 39.59867618100003], [-88.51013447299994, 39.598627005000026], [-88.51012984699997, 39.59867148400008], [-88.50989554699999, 39.59865743300003], [-88.50994180899994, 39.59821264900006]]]}}, {'attributes': {'FID': 5, 'ID': 5, 'GRIDCODE': 6133198, 'val_float': 6.133198, 'Shape_Length': 0.0015985259884337597, 'Shape_Area': 1.5729357874616028e-07}, 'geometry': {'rings': [[[-88.50959036199998, 39.59819157100003], [-88.50994180899994, 39.59821264900006], [-88.50989554699999, 39.59865743300003], [-88.50954409799994, 39.59863635500005], [-88.50959036199998, 39.59819157100003]]]}}, {'attributes': {'FID': 6, 'ID': 6, 'GRIDCODE': 6133198, 'val_float': 6.133198, 'Shape_Length': 0.0036717199087141035, 'Shape_Area': 1.337004565097276e-07}, 'geometry': {'rings': [[[-88.51723432899996, 39.59779942800003], [-88.51722970699996, 39.59784390600004], [-88.51652681299998, 39.59780179100005], [-88.51652219099998, 39.59784627000005], [-88.51581929699995, 39.59780415100005], [-88.51581467399996, 39.597848629000055], [-88.51552180199997, 39.59783107800007], [-88.51553566999996, 39.59769764300006], [-88.51723432899996, 39.59779942800003]]]}}, {'attributes': {'FID': 7, 'ID': 7, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.0036944009223015203, 'Shape_Area': 8.31029074367672e-07}, 'geometry': {'rings': [[[-88.51330984799995, 39.59756423400006], [-88.51424703499998, 39.59762041100004], [-88.51421929399999, 39.597887282000045], [-88.51427786899995, 39.59789079300003], [-88.51421776299998, 39.598469014000045], [-88.51322198999998, 39.598409325000034], [-88.51330984799995, 39.59756423400006]]]}}, {'attributes': {'FID': 8, 'ID': 8, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.002638165788220079, 'Shape_Area': 3.6963599353205685e-07}, 'geometry': {'rings': [[[-88.50956111399995, 39.59733945700003], [-88.51002970499997, 39.597367560000066], [-88.50994180899994, 39.59821264900006], [-88.50959036199998, 39.59819157100003], [-88.50953178799995, 39.59818805800006], [-88.50958267799996, 39.59769879700008], [-88.50952410299999, 39.597695284000054], [-88.50956111399995, 39.59733945700003]]]}}, {'attributes': {'FID': 9, 'ID': 9, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.0011011558185239335, 'Shape_Area': 2.8836806820438634e-08}, 'geometry': {'rings': [[[-88.51887591099995, 39.59731595000005], [-88.51893448499999, 39.59731945800007], [-88.51888365899998, 39.59780872400006], [-88.51882508399996, 39.59780521500005], [-88.51887591099995, 39.59731595000005]]]}}, {'attributes': {'FID': 10, 'ID': 10, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.003929098384089377, 'Shape_Area': 9.018034799649417e-07}, 'geometry': {'rings': [[[-88.51779072899996, 39.59698240800003], [-88.51890363399997, 39.597049078000055], [-88.51887591099995, 39.59731595000005], [-88.51882508399996, 39.59780521500005], [-88.51864936099997, 39.59779468900007], [-88.51864473999996, 39.597839168000064], [-88.51800041899997, 39.59780056900007], [-88.51799579799996, 39.59784504800007], [-88.51770292499998, 39.59782750200003], [-88.51779072899996, 39.59698240800003]]]}}, {'attributes': {'FID': 11, 'ID': 11, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.006041529626108945, 'Shape_Area': 1.842920033707243e-06}, 'geometry': {'rings': [[[-88.51123048899996, 39.59658920900006], [-88.51339770299995, 39.59671914300003], [-88.51330984799995, 39.59756423400006], [-88.51114260799994, 39.59743429900004], [-88.51123048899996, 39.59658920900006]]]}}, {'attributes': {'FID': 12, 'ID': 12, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.009970680531304857, 'Shape_Area': 3.735681323318829e-06}, 'geometry': {'rings': [[[-88.51011759799997, 39.59652247200006], [-88.51123048899996, 39.59658920900006], [-88.51114260799994, 39.59743429900004], [-88.51330984799995, 39.59756423400006], [-88.51322198999998, 39.598409325000034], [-88.51210906999995, 39.59834260500003], [-88.51105472599994, 39.59827938800004], [-88.50994180899994, 39.59821264900006], [-88.51002970499997, 39.597367560000066], [-88.51011759799997, 39.59652247200006]]]}}, {'attributes': {'FID': 13, 'ID': 13, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.0028728673540596075, 'Shape_Area': 4.535194413992171e-07}, 'geometry': {'rings': [[[-88.50953186699996, 39.596487343000035], [-88.51011759799997, 39.59652247200006], [-88.51002970499997, 39.597367560000066], [-88.50956111399995, 39.59733945700003], [-88.50957499299994, 39.59720602200008], [-88.50951641899997, 39.597202509000056], [-88.50956730899998, 39.596713247000025], [-88.50950873599999, 39.59670973400006], [-88.50953186699996, 39.596487343000035]]]}}, {'attributes': {'FID': 14, 'ID': 14, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.006041494569340292, 'Shape_Area': 1.8429027563706388e-06}, 'geometry': {'rings': [[[-88.51571132699996, 39.59600745800003], [-88.51787853199994, 39.59613731500008], [-88.51779072899996, 39.59698240800003], [-88.51562349899996, 39.59685255000005], [-88.51571132699996, 39.59600745800003]]]}}, {'attributes': {'FID': 15, 'ID': 15, 'GRIDCODE': 6209930, 'val_float': 6.20993, 'Shape_Length': 0.003929059533513598, 'Shape_Area': 9.46351063453503e-07}, 'geometry': {'rings': [[[-88.51020548999998, 39.595677384000055], [-88.51131836799999, 39.59574412000006], [-88.51123048899996, 39.59658920900006], [-88.51011759799997, 39.59652247200006], [-88.51020548999998, 39.595677384000055]]]}}, {'attributes': {'FID': 16, 'ID': 16, 'GRIDCODE': 6194583, 'val_float': 6.194583, 'Shape_Length': 0.003107565293719425, 'Shape_Area': 5.374008772364368e-07}, 'geometry': {'rings': [[[-88.50950262099997, 39.59563522900004], [-88.51020548999998, 39.595677384000055], [-88.51011759799997, 39.59652247200006], [-88.50953186699996, 39.596487343000035], [-88.50955962499995, 39.59622047300007], [-88.50950105199996, 39.59621696000005], [-88.50955194099998, 39.595727699000065], [-88.50949336799994, 39.59572418600004], [-88.50950262099997, 39.59563522900004]]]}}, {'attributes': {'FID': 17, 'ID': 17, 'GRIDCODE': 6133198, 'val_float': 6.133198, 'Shape_Length': 0.005628345217491154, 'Shape_Area': 1.7249287892405484e-06}, 'geometry': {'rings': [[[-88.51884491999994, 39.595344854000075], [-88.51890349299998, 39.59534836300003], [-88.51885728799994, 39.59579314900003], [-88.51891586099998, 39.59579665800004], [-88.51886503599997, 39.59628592300004], [-88.51892360899996, 39.59628943200005], [-88.51886816299998, 39.59682317600004], [-88.51892673699996, 39.596826684000064], [-88.51890363399997, 39.597049078000055], [-88.51779072899996, 39.59698240800003], [-88.51787853199994, 39.59613731500008], [-88.51796633199996, 39.59529222100008], [-88.51884491999994, 39.595344854000075]]]}}, {'attributes': {'FID': 18, 'ID': 18, 'GRIDCODE': 6133198, 'val_float': 6.133198, 'Shape_Length': 0.003839573623519977, 'Shape_Area': 8.965232654575615e-07}, 'geometry': {'rings': [[[-88.51254377699996, 39.594161635000034], [-88.51365663399997, 39.59422835100003], [-88.51357340799996, 39.59502896200007], [-88.51246053899996, 39.59496224600008], [-88.51254377699996, 39.594161635000034]]]}}, {'attributes': {'FID': 19, 'ID': 19, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.003722217982682756, 'Shape_Area': 8.493370712925333e-07}, 'geometry': {'rings': [[[-88.51254377699996, 39.594161635000034], [-88.51246053899996, 39.59496224600008], [-88.51140624399994, 39.59489903100007], [-88.51148949399999, 39.59409842100007], [-88.51254377699996, 39.594161635000034]]]}}, {'attributes': {'FID': 20, 'ID': 20, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.003811638143079214, 'Shape_Area': 8.965163616922709e-07}, 'geometry': {'rings': [[[-88.51708302499998, 39.59358334600006], [-88.51813730499998, 39.59364651300007], [-88.51804950899998, 39.594491606000076], [-88.51699521599994, 39.59442843900007], [-88.51708302499998, 39.59358334600006]]]}}, {'attributes': {'FID': 21, 'ID': 21, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.003928991011995116, 'Shape_Area': 9.46322702250636e-07}, 'geometry': {'rings': [[[-88.51708302499998, 39.59358334600006], [-88.51699521599994, 39.59442843900007], [-88.51588235299994, 39.594361753000044], [-88.51597017499995, 39.59351666100008], [-88.51708302499998, 39.59358334600006]]]}}, {'attributes': {'FID': 22, 'ID': 22, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.009467877741262485, 'Shape_Area': 3.685712034533417e-06}, 'geometry': {'rings': [[[-88.51374448099995, 39.59338326000005], [-88.51485732699996, 39.59344996600004], [-88.51476949299996, 39.59429505700007], [-88.51588235299994, 39.594361753000044], [-88.51579915199994, 39.59516236600007], [-88.51468627899999, 39.595095669000045], [-88.51459844099998, 39.595940760000076], [-88.51348555699997, 39.595874053000045], [-88.51357340799996, 39.59502896200007], [-88.51365663399997, 39.59422835100003], [-88.51374448099995, 39.59338326000005]]]}}, {'attributes': {'FID': 23, 'ID': 23, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.003928986501333554, 'Shape_Area': 9.46320575619545e-07}, 'geometry': {'rings': [[[-88.51263163699997, 39.59331654500005], [-88.51374448099995, 39.59338326000005], [-88.51365663399997, 39.59422835100003], [-88.51254377699996, 39.594161635000034], [-88.51263163699997, 39.59331654500005]]]}}, {'attributes': {'FID': 24, 'ID': 24, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.03044815268928624, 'Shape_Area': 1.4161114839896085e-05}, 'geometry': {'rings': [[[-88.51157736599998, 39.593253333000064], [-88.51263163699997, 39.59331654500005], [-88.51254377699996, 39.594161635000034], [-88.51148949399999, 39.59409842100007], [-88.51140624399994, 39.59489903100007], [-88.51246053899996, 39.59496224600008], [-88.51357340799996, 39.59502896200007], [-88.51348555699997, 39.595874053000045], [-88.51459844099998, 39.595940760000076], [-88.51571132699996, 39.59600745800003], [-88.51562349899996, 39.59685255000005], [-88.51779072899996, 39.59698240800003], [-88.51770292499998, 39.59782750200003], [-88.51723432899996, 39.59779942800003], [-88.51553566999996, 39.59769764300006], [-88.51552180199997, 39.59783107800007], [-88.51505320599995, 39.59780299600004], [-88.51504858299995, 39.59784747400005], [-88.51457998799998, 39.59781939000004], [-88.51459385699997, 39.59768595400004], [-88.51453528299999, 39.59768244300005], [-88.51456764599999, 39.59737109400004], [-88.51450907199995, 39.59736758300005], [-88.51451831799994, 39.59727862600005], [-88.51440116999999, 39.59727160500006], [-88.51440579399997, 39.597227126000064], [-88.51434721999999, 39.597223615000075], [-88.51436571299996, 39.59704570100007], [-88.51430713899998, 39.59704219100007], [-88.51434874999995, 39.596641884000064], [-88.51411445599996, 39.59662784100004], [-88.51406359699996, 39.59711710400006], [-88.51412217099994, 39.59712061500005], [-88.51409442999994, 39.59738748600006], [-88.51415300399998, 39.59739099700005], [-88.51414838099998, 39.597435475000054], [-88.51420695499996, 39.59743898600004], [-88.51420233099998, 39.59748346500004], [-88.51426090499996, 39.59748697600003], [-88.51424703499998, 39.59762041100004], [-88.51330984799995, 39.59756423400006], [-88.51339770299995, 39.59671914300003], [-88.51123048899996, 39.59658920900006], [-88.51131836799999, 39.59574412000006], [-88.51020548999998, 39.595677384000055], [-88.50950262099997, 39.59563522900004], [-88.50954425699996, 39.59523492400007], [-88.50948568499996, 39.59523141100004], [-88.50953657299999, 39.59474215000006], [-88.50947800099999, 39.594738637000034], [-88.50952888899997, 39.59424937600005], [-88.50947031799996, 39.594245863000026], [-88.50949807499995, 39.593978993000064], [-88.51037664099994, 39.59403168600005], [-88.51046452699995, 39.593186598000045], [-88.51157736599998, 39.593253333000064]]]}}, {'attributes': {'FID': 25, 'ID': 25, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.012317283109817109, 'Shape_Area': 4.7315637028055076e-06}, 'geometry': {'rings': [[[-88.51271949599999, 39.592471456000055], [-88.51383232599994, 39.59253817100006], [-88.51494515899998, 39.59260487500006], [-88.51717083099999, 39.59273825400004], [-88.51708302499998, 39.59358334600006], [-88.51597017499995, 39.59351666100008], [-88.51588235299994, 39.594361753000044], [-88.51476949299996, 39.59429505700007], [-88.51485732699996, 39.59344996600004], [-88.51374448099995, 39.59338326000005], [-88.51263163699997, 39.59331654500005], [-88.51271949599999, 39.592471456000055]]]}}, {'attributes': {'FID': 26, 'ID': 26, 'GRIDCODE': 6209930, 'val_float': 6.20993, 'Shape_Length': 0.003811605569638687, 'Shape_Area': 8.965018769536028e-07}, 'geometry': {'rings': [[[-88.51271949599999, 39.592471456000055], [-88.51263163699997, 39.59331654500005], [-88.51157736599998, 39.593253333000064], [-88.51166523699999, 39.59240824400007], [-88.51271949599999, 39.592471456000055]]]}}, {'attributes': {'FID': 27, 'ID': 27, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.01885149117276659, 'Shape_Area': 7.866857870949534e-06}, 'geometry': {'rings': [[[-88.51884001999997, 39.59198790600004], [-88.51883539999994, 39.59203238500004], [-88.51889396999997, 39.59203589300006], [-88.51883390699999, 39.59261411500006], [-88.51889247699995, 39.59261762400007], [-88.51883703299995, 39.593151367000075], [-88.51889560399997, 39.59315487600003], [-88.51883553999994, 39.59373309800003], [-88.51889411099995, 39.59373660600005], [-88.51883404599994, 39.59431482800005], [-88.51889261799994, 39.59431833700006], [-88.51883717299995, 39.594852081000056], [-88.51889574499995, 39.594855589000076], [-88.51884491999994, 39.595344854000075], [-88.51796633199996, 39.59529222100008], [-88.51787853199994, 39.59613731500008], [-88.51571132699996, 39.59600745800003], [-88.51459844099998, 39.595940760000076], [-88.51468627899999, 39.595095669000045], [-88.51579915199994, 39.59516236600007], [-88.51588235299994, 39.594361753000044], [-88.51699521599994, 39.59442843900007], [-88.51804950899998, 39.594491606000076], [-88.51813730499998, 39.59364651300007], [-88.51708302499998, 39.59358334600006], [-88.51717083099999, 39.59273825400004], [-88.51822509999994, 39.59280142000006], [-88.51831289199998, 39.59195632700005], [-88.51884001999997, 39.59198790600004]]]}}, {'attributes': {'FID': 28, 'ID': 28, 'GRIDCODE': 6194583, 'val_float': 6.194583, 'Shape_Length': 0.0061585869312700174, 'Shape_Area': 1.8925980466748993e-06}, 'geometry': {'rings': [[[-88.51503298999995, 39.59175978400003], [-88.51725863499996, 39.591893162000076], [-88.51717083099999, 39.59273825400004], [-88.51494515899998, 39.59260487500006], [-88.51503298999995, 39.59175978400003]]]}}, {'attributes': {'FID': 29, 'ID': 29, 'GRIDCODE': 6209930, 'val_float': 6.20993, 'Shape_Length': 0.003928933842830461, 'Shape_Area': 9.462981720020912e-07}, 'geometry': {'rings': [[[-88.51392016999995, 39.591693081000074], [-88.51503298999995, 39.59175978400003], [-88.51494515899998, 39.59260487500006], [-88.51383232599994, 39.59253817100006], [-88.51392016999995, 39.591693081000074]]]}}, {'attributes': {'FID': 30, 'ID': 30, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.004046273605907161, 'Shape_Area': 9.489154828406345e-07}, 'geometry': {'rings': [[[-88.50946891099994, 39.591426168000055], [-88.51064029199995, 39.59149642300008], [-88.51055240999995, 39.59234151100003], [-88.50949815499996, 39.59227828000007], [-88.50951203299996, 39.592144845000064], [-88.50945346399999, 39.59214133200004], [-88.50950897599995, 39.59160759400004], [-88.50945040699997, 39.59160408100007], [-88.50946891099994, 39.591426168000055]]]}}, {'attributes': {'FID': 31, 'ID': 31, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.006158533436829386, 'Shape_Area': 1.8925745630075592e-06}, 'geometry': {'rings': [[[-88.51512081799996, 39.59091469400005], [-88.51734643799995, 39.591048070000056], [-88.51725863499996, 39.591893162000076], [-88.51503298999995, 39.59175978400003], [-88.51512081799996, 39.59091469400005]]]}}, {'attributes': {'FID': 32, 'ID': 32, 'GRIDCODE': 6194583, 'val_float': 6.194583, 'Shape_Length': 0.003928906214608778, 'Shape_Area': 9.462863853716258e-07}, 'geometry': {'rings': [[[-88.51400801099999, 39.59084799100003], [-88.51512081799996, 39.59091469400005], [-88.51503298999995, 39.59175978400003], [-88.51392016999995, 39.591693081000074], [-88.51400801099999, 39.59084799100003]]]}}, {'attributes': {'FID': 33, 'ID': 33, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.0060411731173444045, 'Shape_Area': 1.8427661507794336e-06}, 'geometry': {'rings': [[[-88.51184097199996, 39.59071806800006], [-88.51400801099999, 39.59084799100003], [-88.51392016999995, 39.591693081000074], [-88.51175310499997, 39.59156315600006], [-88.51184097199996, 39.59071806800006]]]}}, {'attributes': {'FID': 34, 'ID': 34, 'GRIDCODE': 6194583, 'val_float': 6.194583, 'Shape_Length': 0.017945360777829978, 'Shape_Area': 7.36854048287871e-06}, 'geometry': {'rings': [[[-88.50949823499997, 39.59057756800007], [-88.50961537199998, 39.59058459400006], [-88.51072817099998, 39.590651336000064], [-88.51184097199996, 39.59071806800006], [-88.51175310499997, 39.59156315600006], [-88.51392016999995, 39.591693081000074], [-88.51383232599994, 39.59253817100006], [-88.51271949599999, 39.592471456000055], [-88.51166523699999, 39.59240824400007], [-88.51157736599998, 39.593253333000064], [-88.51046452699995, 39.593186598000045], [-88.51037664099994, 39.59403168600005], [-88.50949807499995, 39.593978993000064], [-88.50952120499994, 39.59375660200004], [-88.50946263499998, 39.593753089000074], [-88.50951352199996, 39.59326382800003], [-88.50945495099995, 39.593260315000066], [-88.50951046399996, 39.592726576000075], [-88.50945189399994, 39.59272306300005], [-88.50949815499996, 39.59227828000007], [-88.51055240999995, 39.59234151100003], [-88.51064029199995, 39.59149642300008], [-88.50946891099994, 39.591426168000055], [-88.50951054499996, 39.59102586400007], [-88.50945197599998, 39.59102235000006], [-88.50949823499997, 39.59057756800007]]]}}, {'attributes': {'FID': 35, 'ID': 35, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.010410870956705771, 'Shape_Area': 3.5387468787020875e-06}, 'geometry': {'rings': [[[-88.51081142299995, 39.589850727000055], [-88.51520402199998, 39.59011408200007], [-88.51512081799996, 39.59091469400005], [-88.51400801099999, 39.59084799100003], [-88.51184097199996, 39.59071806800006], [-88.51072817099998, 39.590651336000064], [-88.51081142299995, 39.589850727000055]]]}}, {'attributes': {'FID': 36, 'ID': 36, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.003839436436928898, 'Shape_Area': 8.964679314148332e-07}, 'geometry': {'rings': [[[-88.50969863699999, 39.58978398600004], [-88.51081142299995, 39.589850727000055], [-88.51072817099998, 39.590651336000064], [-88.50961537199998, 39.59058459400006], [-88.50969863699999, 39.58978398600004]]]}}, {'attributes': {'FID': 37, 'ID': 37, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.002079238763787721, 'Shape_Area': 1.4679013026007152e-07}, 'geometry': {'rings': [[[-88.50946436599997, 39.58976993400006], [-88.50969863699999, 39.58978398600004], [-88.50961537199998, 39.59058459400006], [-88.50949823499997, 39.59057756800007], [-88.50950748699995, 39.59048861200006], [-88.50944891899996, 39.590485099000034], [-88.50950442999994, 39.58995136000004], [-88.50944586199995, 39.589947847000076], [-88.50946436599997, 39.58976993400006]]]}}, {'attributes': {'FID': 38, 'ID': 38, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.0007376905254126123, 'Shape_Area': 2.6212223721738452e-08}, 'geometry': {'rings': [[[-88.50971251399994, 39.58965055200008], [-88.50969863699999, 39.58978398600004], [-88.50946436599997, 39.58976993400006], [-88.50947361799996, 39.58968097800005], [-88.50959075299994, 39.58968800400004], [-88.50959537899996, 39.58964352600003], [-88.50971251399994, 39.58965055200008]]]}}, {'attributes': {'FID': 39, 'ID': 39, 'GRIDCODE': 6194583, 'val_float': 6.194583, 'Shape_Length': 0.0025873140290852232, 'Shape_Area': 1.5989412200851147e-07}, 'geometry': {'rings': [[[-88.51082992299996, 39.58967281400004], [-88.51081142299995, 39.589850727000055], [-88.50969863699999, 39.58978398600004], [-88.50971251399994, 39.58965055200008], [-88.51059102799996, 39.58970324300003], [-88.51059565299994, 39.589658764000035], [-88.51082992299996, 39.58967281400004]]]}}, {'attributes': {'FID': 40, 'ID': 40, 'GRIDCODE': 6148544, 'val_float': 6.148544, 'Shape_Length': 0.003213378725966996, 'Shape_Area': 5.268694780013576e-07}, 'geometry': {'rings': [[[-88.51748044799996, 39.58975819300008], [-88.51742961699995, 39.59024745700003], [-88.51631681799995, 39.59018077500008], [-88.51636303499998, 39.589735990000065], [-88.51683157899998, 39.58976406800008], [-88.51683619999994, 39.589719589000026], [-88.51748044799996, 39.58975819300008]]]}}, {'attributes': {'FID': 41, 'ID': 41, 'GRIDCODE': 6179237, 'val_float': 6.179237, 'Shape_Length': 0.0018667435968832725, 'Shape_Area': 1.992145285392513e-07}, 'geometry': {'rings': [[[-88.51854391399996, 39.58973239900007], [-88.51883675399995, 39.58974994300007], [-88.51882751399995, 39.589838900000075], [-88.51888608199994, 39.58984240900003], [-88.51883525999995, 39.59033167300004], [-88.51848384899995, 39.590310620000025], [-88.51854391399996, 39.58973239900007]]]}}, {'attributes': {'FID': 42, 'ID': 42, 'GRIDCODE': 6163890, 'val_float': 6.16389, 'Shape_Length': 0.023493996027768395, 'Shape_Area': 7.3945455664565385e-06}, 'geometry': {'rings': [[[-88.51854391399996, 39.58973239900007], [-88.51848384899995, 39.590310620000025], [-88.51883525999995, 39.59033167300004], [-88.51882601999995, 39.59042063000004], [-88.51888458899998, 39.59042413900005], [-88.51882914699996, 39.590957881000065], [-88.51888771599994, 39.590961390000075], [-88.51883227299999, 39.59149513300008], [-88.51889084299995, 39.59149864200003], [-88.51884001999997, 39.59198790600004], [-88.51831289199998, 39.59195632700005], [-88.51822509999994, 39.59280142000006], [-88.51717083099999, 39.59273825400004], [-88.51725863499996, 39.591893162000076], [-88.51734643799995, 39.591048070000056], [-88.51512081799996, 39.59091469400005], [-88.51520402199998, 39.59011408200007], [-88.51081142299995, 39.589850727000055], [-88.51082992299996, 39.58967281400004], [-88.51164987099997, 39.58972198600003], [-88.51165449499996, 39.58967750700003], [-88.51265014599994, 39.58973720800003], [-88.51265476999998, 39.589692730000024], [-88.51365042199996, 39.58975242200006], [-88.51365504599994, 39.589707944000054], [-88.51453356299999, 39.58976060700007], [-88.51453818599998, 39.58971612900007], [-88.51529956799999, 39.58976176500005], [-88.51530419099998, 39.58971728700004], [-88.51606557299993, 39.589762919000066], [-88.51607019499994, 39.58971844000007], [-88.51636303499998, 39.589735990000065], [-88.51631681799995, 39.59018077500008], [-88.51742961699995, 39.59024745700003], [-88.51748044799996, 39.58975819300008], [-88.51753901599994, 39.58976170300008], [-88.51754363699996, 39.589717224000026], [-88.51830502099995, 39.58976284200003], [-88.51830964099997, 39.58971836400008], [-88.51854391399996, 39.58973239900007]]]}}], 'exceededTransferLimit': False}}, {'paramName': 'TableOutput', 'dataType': 'GPRecordSet', 'value': {'displayFieldName': '', 'fields': [{'name': 'OID', 'type': 'esriFieldTypeOID', 'alias': 'OID'}, {'name': 'Value', 'type': 'esriFieldTypeInteger', 'alias': 'Value'}, {'name': 'Count', 'type': 'esriFieldTypeDouble', 'alias': 'Count'}, {'name': 'val_float', 'type': 'esriFieldTypeDouble', 'alias': 'val_float'}], 'features': [{'attributes': {'OID': 0, 'Value': 6133198, 'Count': 1249, 'val_float': 6.133198}}, {'attributes': {'OID': 1, 'Value': 6148544, 'Count': 5327, 'val_float': 6.148544}}, {'attributes': {'OID': 2, 'Value': 6163890, 'Count': 7462, 'val_float': 6.16389}}, {'attributes': {'OID': 3, 'Value': 6179237, 'Count': 10927, 'val_float': 6.179237}}, {'attributes': {'OID': 4, 'Value': 6194583, 'Count': 4160, 'val_float': 6.194583}}, {'attributes': {'OID': 5, 'Value': 6209930, 'Count': 1186, 'val_float': 6.20993}}], 'exceededTransferLimit': False}}, {'paramName': 'LegendRangeValues', 'dataType': 'GPString', 'value': [[6.12552499771118, 6.1408713658650695, 6.133198], [6.1408713658650695, 6.156217734018959, 6.148544], [6.156217734018959, 6.171564102172849, 6.16389], [6.171564102172849, 6.186910470326739, 6.179237], [6.186910470326739, 6.202256838480628, 6.194583], [6.202256838480628, 6.217603206634518, 6.20993]]}], 'messages': []}

Displaying Table

In [6]:
df=defaultdict(list)
resolution=5
areaOfOnePixel=resolution*resolution
totalpixels = 0
for value in polaris['results'][3]['value']: 
    val=str(round(value[0] * 100) / 100) + "-" + str(round(value[1] * 100) / 100)
    df[SoilValue].append(val)
for value in polaris['results'][2]['value']['features']: 
    totalpixels+=value['attributes']['Count']

totalArea=(totalpixels * areaOfOnePixel) * 0.000247105

for value in polaris['results'][2]['value']['features']: 
    partAcres = (value['attributes']['Count'] * areaOfOnePixel) * 0.000247105
    percentAcres = (partAcres / totalArea) * 100
    df['Area per Part (Acres)'].append(round(partAcres * 100) / 100)
    df['% of Total'].append(round(percentAcres * 100) / 100)

soil=pd.DataFrame.from_dict(df)
soil
Out[6]:
ph Area per Part (Acres) % of Total
0 6.13-6.14 7.72 4.12
1 6.14-6.16 32.91 17.57
2 6.16-6.17 46.10 24.62
3 6.17-6.19 67.50 36.05
4 6.19-6.2 25.70 13.72
5 6.2-6.22 7.33 3.91

Displaying Map

Helper Functions

In [7]:
def post_converttogeojson(requestbody):
    try:
        url = "https://ogre.adc4gis.com/convert"
     
        response = (requests.post(url,files=requestbody).text)
        
        return response

    except Exception as e:
        raise e
def post_converttoshapefile(requestbody):
    try:
        url = "https://ogre.adc4gis.com/convertJson"
     
        response = (requests.post(url,data=requestbody))
        
        z = zipfile.ZipFile(io.BytesIO(response.content))
        z.extractall("./shapefiles/")
        
        time.sleep(0.5)
        return response
    
    except Exception as e:
        raise e
In [8]:
requestbody={'upload':open('./jsonfiles/polarisdata1.json','rb')}

polarisdata_geojson=post_converttogeojson(requestbody)
requestbody={'json':polarisdata_geojson,'skipFailures':"on"}
post_converttoshapefile(requestbody)
Out[8]:
<Response [200]>

Displaying Output Map

In [10]:
gdf = gpd.read_file('./shapefiles/OGRGeoJSON.shp')
gdf.plot(column='val_float', cmap=None,figsize=(10, 10),legend=True) 
gdf.head()
Out[10]:
FID ID GRIDCODE val_float Shape_Leng Shape_Area geometry
0 1 1 6179237 6.179237 0.002532 0.0 POLYGON ((-88.51322198999998 39.59840932500003...
1 2 2 6209930 6.209930 0.002856 0.0 POLYGON ((-88.51210906999995 39.59834260500003...
2 3 3 6133198 6.133198 0.002828 0.0 POLYGON ((-88.51105472599994 39.59827938800004...
3 4 4 6148544 6.148544 0.003124 0.0 POLYGON ((-88.50994180899994 39.59821264900006...
4 5 5 6133198 6.133198 0.001599 0.0 POLYGON ((-88.50959036199998 39.59819157100003...
In [ ]: