Is there a way to get the total count of features in a single service with python?
If you are using the Python API, see: arcgis.features.FeatureLayer.query
and use return_count_only=True
See: Query (Feature Service)
The Query operation is performed on a feature service resource. The result of this operation is either a feature set for each layer in the query or a count of features for each layer (if returnCountOnly is set to true) or an array of feature IDs for each layer in the query (if returnIdsOnly is set to true).
I did a quick test, with returnCountOnly set to true and using a where "1=1". It returned a count.
URL <SPAN class="operator token">=</SPAN> <SPAN class="string token">"https://services.arcgis.com/xyz/arcgis/rest/services/myFeature/FeatureServer/0/query"</SPAN> query_dict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"where"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"1=1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"returnCountOnly"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"true"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"returnGeometry"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"false"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">:</SPAN> token<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">}</SPAN> jsonResponse <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>URL<SPAN class="punctuation token">,</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN>query_dict<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> response <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>jsonResponse<SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> response <SPAN class="comment token"># prints: {u'count': 486, u'serverGens': {u'serverGen': 461482, u'minServerGen': 65364}}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.