0

I did a python script to do a query from the UF field from my attribute table. The code is very simple and works well. The output show me a map with the selected values.

Now I neeed to sum the values from another field (lets call this field "NEW") only from the selected features from UF field.

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT") 
for lyr in arcpy.mapping.ListLayers(mxd): 
 if lyr.name == "Brasil_Municipios": 
 lyr.definitionQuery = "UF = 'GO'" 
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

I can get the SUM with Summary Tool, but how to print in the screen the result?

import arcpy 
mxd = arcpy.mapping.MapDocument("CURRENT") 
fc = 'G:\AgroBD.gdb\Brasil_Municipios'
for lyr in arcpy.mapping.ListLayers(mxd): 
 if lyr.name == "Brasil_Municipios": 
 lyr.definitionQuery = "UF = 'GO'" 
 arcpy.Statistics_analysis("Brasil_Municipios", 
 "G:\AgroBD.gdb\Brasil_Municipios2", [["media", "SUM"]], "")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 9, 2017 at 20:18

1 Answer 1

3

To summarize a field I would always use the Summary Statistics tool which I would expect to honour any current selection if used against a feature layer or table view.

I would use a SearchCursor to read the row that has the result you want first. Then, depending on whether your active view is the Layout View or the Data View, I would either update the text in a text element or update the value in a labeled point feature that you guarantee to be in the currently viewed extent.

answered Jul 9, 2017 at 20:21
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.