|
POST
|
Jake- Thank you for the script for ArcMap 10.0 It looks good - but - I have tried the script in ArcCatalog and ArcMap and each time - it crashes and get the "ArcGIS Desktop has encountered a serious application error and is unable to continue" Error screen.
... View more
08-30-2013
06:45 AM
|
0
|
0
|
1427
|
|
POST
|
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. 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?
... View more
08-29-2013
08:22 AM
|
0
|
0
|
1427
|
|
POST
|
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.
... View more
08-29-2013
06:54 AM
|
0
|
0
|
1427
|
|
POST
|
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. Okay - so far this is an awesome start. I am atleast getting the script to run without any errors and the .PDF is coming out - but the graph is not showing the data.... no worries. This is something for me to build off of...... The thing I want to do is to be able to run a script that will do these for Each meter (around 9500 total) at one time. This current script works for on demand graphs. Thanks alot so far
... View more
08-28-2013
02:56 PM
|
0
|
0
|
1427
|
|
POST
|
Not sure if this makes a difference at all - but I am currently running ArcMap 10.0 and using Python 2.6. I am using IDLE to edit and run the script. Is this making a difference in the code and how its running? I am planning on upgrading to ArcMap 10.2 in the next week.
... View more
08-28-2013
02:10 PM
|
0
|
0
|
2462
|
|
POST
|
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? This is what I see
... View more
08-28-2013
12:32 PM
|
0
|
0
|
2462
|
|
POST
|
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 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 e ExecuteError: 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).
... View more
08-28-2013
12:23 PM
|
0
|
0
|
2462
|
|
POST
|
Attached is a zip file with an example. Try the following: 1. Extract the zip file to your C:\Temp directory 2. Open ArcMap 3. Under C:\Temp, expand the Data.gdb > Graph toolbox > double-click on the Script 4. Specify a meter number, i.e. 8151830 5. Click OK to execute the tool Within your C:\Temp directory you should have a graph as a PDF. Is this what you are looking for? 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
... View more
08-28-2013
11:43 AM
|
0
|
0
|
2462
|
|
POST
|
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. Jake- Sounds like I have most of the parts....a good part of them from you...and I really appreciate that. The biggest headache right now is I cannot figure out the Script for the Search Cursor to isolate individual meter number records to produce a single graph for a specific meter number
... View more
08-28-2013
11:10 AM
|
0
|
0
|
2535
|
|
POST
|
Your fields need to be a list. http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000 Instead 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? Jake- What I am trying to do is to take a File Geodatabase Table that lists Electric Meters with their Peak KW Demand on a given billing period to eventually make a graph. See previous posts in this thread for full explination. I am having a heck of a time with this Search Cursor just trying to get a list of unique meter numbers with all of the rest of the data and isolating the rows of the same meter number
... View more
08-28-2013
10:50 AM
|
0
|
0
|
2535
|
|
POST
|
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.gdb illing" does not exist
... View more
08-28-2013
10:37 AM
|
0
|
0
|
2535
|
|
POST
|
Excellent! It is great that you have written out a plan, many people don't and then get hopelessly lost... It definitely looks possible. Right now we'll get step 1 partly working, just printing to screen. Once that is good we can put the data in a useful data structure, rather than just printing it. I think James' suggestion, of using Pandas, is good. I haven't used it myself, but I think it works pretty well with time data and plotting functions. So there is something else you will need to look up and have a play with... Do you intend to only ever assess one meter at a time? You have a few options, but for now we may as well keep part 1 collecting all the data, and between part 1 and part 2 define the one METER NUMBER to make the graph of. Stacy- Thank you for the posts. So far - I do not have much code written since I am still in the research and design phase of this project to get to the final outcome. Really looking for advice and maybe examples of different parts of the overall Python code. So far - I have some great information from different people to research and start doing some trial and error. The only thing I do not have yet: How do I go about taking a Python script and making a "One-Click" custom button in ArcMap that when someone clicks on it - it runs the Python Script in the background?
... View more
08-28-2013
07:08 AM
|
0
|
0
|
342
|
|
POST
|
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) Jake- Thank you for the Python Script for creating a graph. I will work with that and see what I can come up with
... View more
08-28-2013
07:05 AM
|
0
|
0
|
2535
|
|
POST
|
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 this the 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. Cheers Dave Dave- Thank you for the Python script to find the unique Meter Number and export them out. I will play with this and see what I can come up with.
... View more
08-28-2013
07:03 AM
|
0
|
0
|
2535
|
|
POST
|
What I have is a table I produced from our Customer Information System showing the billed KWH Usage and KW Demand for a ALL electric meters over a period of time (From July 2011 to July 2013). There are about 900,000 records in this table of around 9500 electric meters. What I am trying to accomplish is listed below: Attached: Example.xlsx This is also in a File Geodatabase as a Geodatabase Table This table is composed of around 9500 meter records (METER NUMBER) 1) Go through the table and find METER NUMBER record with the billing period, KWH and KW Demand rows attached. 2) Extract/export/select a unique METER NUMBER with the data attached (billing period, KWH and KW Demand) 3) Take the data and build a graph showing the Billing Period along the "X" Axis, KWH and KW Demand along the "Y" Axis 4) Export the graph to a .PDF with the METER NUMBER as the file name From there I can use the Attachments Geoprocessing tool to take the .PDF and attach it to the Meter Location in the .MXD Long Term Goal is to create a One-Touch custom Button to select a specific METER NUMBER to create a graph described above and automatically create a .PDF. I know this sounds like a huge project - and want to learn how to build it piece by piece to eventually accomplish the Long Term Goal. Thanks for your help in advanced
... View more
08-27-2013
09:17 AM
|
1
|
32
|
7940
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-20-2025 02:52 PM | |
| 1 | 10-30-2025 12:42 PM | |
| 1 | 10-16-2025 10:51 AM | |
| 1 | 08-27-2025 08:47 AM | |
| 1 | 06-17-2025 07:40 AM |
| Online Status |
Offline
|
| Date Last Visited |
Tuesday
|