I am using an API to pull in some Web Mapping Service Layer data to my script. The API query has a max count limit of 1000 on returned features per request. There are 2 attributes I am trying to use in my query 1) A DFIRM_ID field that has the same value for multiple features (its not unique but there are many DFIRM_ID values) and 2) The OBJECTID -this is a totally unique value. Each feature has its own OBJECTID. My goal is to get the total number of OBJECTID's for a given DFIRM_ID (or the total number of features). So, I want to use Output Statistics in my query. Which also requires 'Group By Fields'. According to the ArcGIS REST API documentation, I believe I should have ``. But the outputStatistics part seems confusing (as to how to put it in my query. The documentation says the following syntax (or something like it) is to be used:

"statisticType": "<count | sum | min | max | avg | stddev | var>",
"onStatisticField": "DFIRM_ID", 
"outStatisticFieldName": "DFIRM_COUNT"

I am just a little confused. How would I use that in my params variable below when plugging it into my code?

params = {'f': 'json', 'where': 'DFIRM_ID like \'13245%\'+'and OBJECTID>='+str(minCount)+'and OBJECTID<='+str(maxCount), 'geometryType': 'esriGeometryPolygon', 'spatialRel': 'esriSpatialRelIntersects','outFields': '*', 'returnGeometry': 'false'}
r = requests.get('https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer/3/query', params)
cslfJson = r.json()
  • 1
    I think something is missing in I believe I should have ``, right? – Berend Sep 28 '18 at 7:19
  • Yep. Sorry, it got removed somehow. – gwydion93 Sep 28 '18 at 17:12

The statistics you need are the count of OBJECTID for each DFIRM_ID, so your onStatisticField should be OBJECTID instead of DFIRM_ID. The groupBy parameter should be set to DFIRM_ID:

    "statisticType": "count",
    "onStatisticField": "OBJECTID", 
    "outStatisticFieldName": "Count"

Which would make your params variable something like this

params = { ....  'groupByFieldsForStatistics': 'DFIRM_ID', 'outStatistics': '[{"statisticType": "count", "onStatisticField": "OBJECTID", "outStatisticFieldName": "Count"}]' }

An easy way to find out what the URL should look like is to use the HTML interface of the rest endpoint: https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer/3/query?f=html

This results in URL (empty parameters removed): https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer/3/query?where=1%3D1&groupByFieldsForStatistics=DFIRM_ID&outStatistics=%5B%7B%22statisticType%22%3A%22count%22%2C%22onStatisticField%22%3A%22OBJECTID%22%2C%22outStatisticFieldName%22%3A%22COUNT%22%7D%5D&f=html

Here are the first few results:

# records: 383

DFIRM_ID: 13245C
COUNT: 8286

DFIRM_ID: 06037C
COUNT: 10632

DFIRM_ID: 17031C
COUNT: 1879

DFIRM_ID: 13115C
COUNT: 2678

DFIRM_ID: 06001C
COUNT: 12788

DFIRM_ID: 04013C
COUNT: 32702

DFIRM_ID: 04025C
COUNT: 2428

DFIRM_ID: 48453C
COUNT: 60419
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.