Dave-Thank you, but how should that look here??:for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n)[:-2] + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel"
for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n)[:-2] + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel"
Sorry meant to add that bit in. Where you specify the name of the PDF and use str(n) use str(n)[:-2]CheersDave
for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel"
import arcpy import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb" table = "SERVICE_METERS_DEMAND_F1FEEDER" list = [] rows = arcpy.SearchCursor(table) for row in rows: list.append(row.TWACs_NUMBER) del row, rows # Remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel" # Create the Graph graph = arcpy.Graph() # Add a Vertical Bar series to the graph - KWH Usage graph.addSeriesBarVertical(input_data, "KWH_USAGE") # Specify the title of the Left Axis graph.graphAxis[0].title = "KWH_USAGE" # Specify the title of the Bottom Axis graph.graphAxis[2].title = "BILLING_PERIOD" # Specify the title of the Graph graph.graphPropsGeneral.title = "KWH Usage by Electric TWACs Number" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an .PDF arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
number = float(123456) print number '123456.0' # where you use the str(number) use a slice to remove the .0 in the pdf name str(number[:-2] '123456'
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" list = [] rows = arcpy.SearchCursor(table) for row in rows: list.append(row.METER_NUMBER) del row, rows #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + str(n) + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an PDF arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
Okay - I am trying to run this script off of ArcMap 10.0... I am in the process of upgrading to 10.2.... What is the latest Python that I will need?
Jake, he's running 10.0. The da cursors didn't show up until 10.1. Also, I don't think 10.0 cursors will take a list for the fields, just a formatted string.
Jake-Thank you for that. Close.....However - I am getting this error:<type 'exceptions.AttributeError'>: 'module' object has no attrbute 'da'Failed to execute
Here is an update to the script that will perform this for each unique meter number:import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" fields = ["METER_NUMBER"] list = [] with arcpy.da.SearchCursor(table, fields) as cursor: for row in cursor: list.append("{0}".format(row[0])) del cursor, row #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + n) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + n + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)If you want to run this from toolbox, right-click on the script within toolbox > Properties > Parameters tab and delete the parameter previously created.
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" fields = ["METER_NUMBER"] list = [] with arcpy.da.SearchCursor(table, fields) as cursor: for row in cursor: list.append("{0}".format(row[0])) del cursor, row #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + n) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + n + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
Right-click on the Script in the toolbox, click the Source tab, and make sure this is set to the script:[ATTACH=CONFIG]27069[/ATTACH]Also, check to make sure the Parameter is set:[ATTACH=CONFIG]27070[/ATTACH]Then, when you double-click on the Script in the toolbox, you should be presented with the following:[ATTACH=CONFIG]27071[/ATTACH]The user can enter in a meter number, and then an output graph will be created like the one attached.
This is what I see
## extract unique records from a gdb table and make mulitple tables for ## graphing import arcpy, os arcpy.env.overwriteOutput = True table = r'H:\Python\test.gdb\billing' fields = ['BILLING_PERIOD','METER_NUMBER','KWH','KW_DEMAND'] # empty list to store unique meter numbers meterNumbers = [] # use a search cursor to extract the unique numbers with arcpy.da.SearchCursor(table,fields) as cursor: for row in cursor: if not row[1] in meterNumbers: meterNumbers.append(row[1]) # for each unique cursor make a table view using the billing number for # the selection for meter in meterNumbers: ## omit the quotes if you table stores the meter number as a number not a string expression = arcpy.AddFieldDelimiters(table,'METER_NUMBER') + " = " + "'" + meter + "'" arcpy.MakeTableView_management(table,"CurrentMeter",expression) # copy the rows to a permanent table in the same location outTable = os.path.join(os.path.dirname(table),("meter_" + meter)) arcpy.CopyRows_management("CurrentMeter",outTable) ## at this point can use the graphing options to generate the graphs and save ## unfortunately don't have the answer yet for this
This is an error I get back:Traceback (most recent call last): File "C:\temp\Script1.py", line 8, in <module> arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + arcpy.GetParameterAsText(0)) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\analysis.py", line 153, in TableSelect raise eExecuteError: ERROR 999999: Error executing function.An invalid SQL statement was used.An invalid SQL statement was used. [Meters]An invalid SQL statement was used. [SELECT * FROM Meters WHERE METER_NUMBER = ]Failed to execute (TableSelect).
arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + arcpy.GetParameterAsText(0))
arcpy.TableSelect_analysis(table, r"in_memory\table_sel", '"METER_NUMBER"' + " = " + arcpy.GetParameterAsText(0))
arcpy.AddFieldDelimiters(table,"METER_NUMBER")
Okay - what is not working here?## extract unique records from a gdb table and make mulitple tables for ## graphing import arcpy, os arcpy.env.overwriteOutput = True table = "C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\billing" fields = "BILLING_PERIOD";"METER_NUMBER";"KWH";"KW_DEMAND" # empty list to store unique meter numbers meterNumbers = [] # use a search cursor to extract the unique numbers with arcpy.SearchCursor(table,fields) as cursor: for row in cursor: if not row[1] in meterNumbers: meterNumbers.append(row[1])This is the error I'm getting:Traceback (most recent call last): File "Z:\Operations\Maps and Records\GeoDatabase\MEWCO GIS System\Python Scripts\SearchCursorExample.py", line 16, in <module> with arcpy.SearchCursor(table,fields) as cursor: File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 820, in SearchCursor return gp.searchCursor(*args) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 357, in searchCursor self._gp.SearchCursor(*gp_fixargs(args)))IOError: "C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdbilling" does not exist
## extract unique records from a gdb table and make mulitple tables for ## graphing import arcpy, os arcpy.env.overwriteOutput = True table = "C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\billing" fields = "BILLING_PERIOD";"METER_NUMBER";"KWH";"KW_DEMAND" # empty list to store unique meter numbers meterNumbers = [] # use a search cursor to extract the unique numbers with arcpy.SearchCursor(table,fields) as cursor: for row in cursor: if not row[1] in meterNumbers: meterNumbers.append(row[1])
You can open ArcMap, and then navigate to C:\temp using the Catalog window. When you double-click on the script within the Toolbox, what do you see? Can you send a screen shot? What meter number did you specify?
Jake- This is a great start - but it doesn't seem to be working according to your instructions. Is it open in ArcMap or ArcCatalog? - Also I dont see a place that asks me to type in a meter number
Attached is a zip file with an example. Try the following:1. Extract the zip file to your C:\Temp directory2. Open ArcMap3. Under C:\Temp, expand the Data.gdb > Graph toolbox > double-click on the Script4. Specify a meter number, i.e. 81518305. Click OK to execute the toolWithin your C:\Temp directory you should have a graph as a PDF. Is this what you are looking for?
That is what the original script that I posted does. What you will need to do is create a sample graph and update the script with the correct paths to your data. Then, create a toolbox > right-click on the toolbox > Add Script > browse to the script. You will also need to add a parameter to the script of type Long. A user can then click on the script and it will open a dialog for them to specify a Meter Number. Once they do and execute the tool, the meter number is queried and the graph is saved to a PDF.
Your fields need to be a list.http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000Instead of:fields = "BILLING_PERIOD";"METER_NUMBER";"KWH";"KW_DEMAND"try:fields = ["BILLING_PERIOD","METER_NUMBER","KWH","KW_DEMAND"]Mind me asking what's the purpose of creating a list of the meter numbers?
fields = "BILLING_PERIOD";"METER_NUMBER";"KWH";"KW_DEMAND"
fields = ["BILLING_PERIOD","METER_NUMBER","KWH","KW_DEMAND"]
Here is an example on how to accomplish this. First, you will want to create a sample graph in ArcMap. Here is a screen shot of the parameters I used:[ATTACH=CONFIG]27045[/ATTACH]After the graph is created, right-click on it and save it out as a .grf file. Now you can use the below code to create a graph of the "KW Demand by Meter" by specifying a meter number:import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\python\test.gdb" table = "Meters" arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + arcpy.GetParameterAsText(0)) out_graph_name = arcpy.GetParameterAsText(0) out_graph_pdf = r"C:\Temp\python\Userdata" + "\\" + arcpy.GetParameterAsText(0) + ".pdf" input_template = r"C:\Temp\Python\UserData\KW Demand.grf" #grf file previously saved input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\python\test.gdb" table = "Meters" arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + arcpy.GetParameterAsText(0)) out_graph_name = arcpy.GetParameterAsText(0) out_graph_pdf = r"C:\Temp\python\Userdata" + "\\" + arcpy.GetParameterAsText(0) + ".pdf" input_template = r"C:\Temp\Python\UserData\KW Demand.grf" #grf file previously saved input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
Hi,Have part of an answer for you, the code below will allow you to extract out the information based on the unique billing numbers within your table. It doesn't yet create and export the graphs but more on that in a minute. Here is the code for extracting the unique billing tables.## extract unique records from a gdb table and make mulitple tables for ## graphing import arcpy, os arcpy.env.overwriteOutput = True table = r'H:\Python\test.gdb\billing' fields = ['BILLING_PERIOD','METER_NUMBER','KWH','KW_DEMAND'] # empty list to store unique meter numbers meterNumbers = [] # use a search cursor to extract the unique numbers with arcpy.da.SearchCursor(table,fields) as cursor: for row in cursor: if not row[1] in meterNumbers: meterNumbers.append(row[1]) # for each unique cursor make a table view using the billing number for # the selection for meter in meterNumbers: ## omit the quotes if you table stores the meter number as a number not a string expression = arcpy.AddFieldDelimiters(table,'METER_NUMBER') + " = " + "'" + meter + "'" arcpy.MakeTableView_management(table,"CurrentMeter",expression) # copy the rows to a permanent table in the same location outTable = os.path.join(os.path.dirname(table),("meter_" + meter)) arcpy.CopyRows_management("CurrentMeter",outTable) ## at this point can use the graphing options to generate the graphs and save ## unfortunately don't have the answer yet for thisthe copy rows at the end is not strictly need as you can do the graph creation in memory for each billing table.If you want to create the graph purely using arcpy and ArcGIS you have a couple of options. There are the make and save graph tools which you can use based on a template graph created in arcmap, all that is required then is to modify the data source for each graph to your current table.Alternatively use the arcpy graph class to carry out all these steps, I believe you will need to use this class to modify the data sources in the previous example. THe save graph will then allow you to export to pdf.There is also matplotlib shipped with arcpy and that may be a better way to create the graphs. Sorry haven't used it so can't give you any steering on utilising it.Hope this helps and gets you started. If i come up with anything I'll post again.CheersDave
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.