|
POST
|
I think I should include an example of the data that I am using to better explain what I am trying to accomplish 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
08:18 AM
|
0
|
0
|
1941
|
|
POST
|
Having a hard time getting multiple fields to show up. I have about (4) fields that I need to show: TWACs_NUMBER PERIOD_ENDS KWH_USAGE KW_DEMAND So Far - I can get the "TWACs_NUMBER to "print" to the screen - but I need all of these fields to "print" so I can sort them by TWACs NUMBER
... View more
08-27-2013
07:43 AM
|
0
|
0
|
1941
|
|
POST
|
Stacy- Thank you for the ideas. I have playing around with the SearchCursor in Python and so far all I am getting it to do is to "Print" to the screen. What else would I have to do to extract this data out? This can definitely be done in Python, but you will have to learn a lot! Here are a few bits to get you started: SearchCursor (10.0), da.SearchCursor (10.2) allows you to iterate through tables and get values. You could store the values (date, reading) within lists in a Python dictionary by meter number. Python datetime module (inbuilt) will be helpful for working with dates. Matplotlib allows you to plot things from Python. I don't know how to make PDFs from Python, but I have no doubt whatsoever that it is possible... I would suggest you start playing around with matplotlib, datetime and searchcursors first, once you are familiar with them, start to think about the data structure that you will use to get the information from the searchcursor, analyse the monthly peak, and pass the result to matplotlib. Happy to help if you have more specific queries!
... View more
08-27-2013
06:57 AM
|
0
|
0
|
1941
|
|
POST
|
Greetings I have a rather large project I am trying to do and I hope I can get Python to do it for me. I have a file geodatabase table called "SERVICE METERS DEMAND" which is basically composed of the peak demand reading on an electric meter for a given month. I have the range of readings from November 2011 to March 2013. The table contains about 172,000 total records with almost 10,000 electric meters. What I want to be able to do is to take an individual meter by number (TWACs Number) and create a graph visually showing the peak demand for each month. This would be used by our engineering department and our meter techs for analysis and decisions making. The big thing is - I update this table about 4 times a year so my geodatabase can have the latest demand readings that other departments use. With that being said, I would like to create a script that can automatically create all new graphs and export them out to a .PDF format. I can than use the Attachment geoprocessing tools to link those .PDF graphs to the meter locations. Do you think this is something that can be done by Python? If so - how do I start this. I currently have ArcMap 10.0 on one machine and in the process of testing a bunch of different tools/processes on ArcMap 10.2 on a different machine. Thank you in advance. Can send a sample of the SERVICE METERS DEMAND table as well
... View more
08-23-2013
06:56 AM
|
0
|
10
|
2496
|
|
POST
|
Greetings- Our company does things a little different. Instead of using ArcGIS Server and web development, we use ArcMAP as our editor and ArcReader as our viewer. I have been getting complaints from different users inside my company that ArcReader 10.0 is unreliable. The largest complaint I get is when they use the "FIND" tool. Sometimes it comes up fast. BUT, most of the time it takes a few minutes for the FIND dialog box to show up. Other times - ArcReader 10.0 completely freezes up and they have to force close it and reopen it. Is this a known issue? Also - Does ArcReader 10.1 and/or ArcReader 10.2 have a better FIND tool and is the new release(s) more reliable than ArcReader 10.0? Thank you
... View more
07-31-2013
10:48 AM
|
0
|
1
|
3441
|
|
POST
|
I was doing some more research on ESRI and I didn't get a chance to go to the International User Conference this year - but saw that ArcMap 10.2 is now out. Did they fix this issue with this new release? Can I install ArcMap 10.2 on my local machine and create a .PMF that can be opened in ArcReader 10.0? Greetings- Having a hard time getting a straight answer on this problem. Does ArcMap 10.1 Service Pack 1 fix the issue with creating a .PMF in ArcMap 10.1 and having the ability to open it in ArcReader 10? I have ArcReader installed on about a dozen machines in my company and will be a pain to go to each one and uninstall 10 and install 10.1 for ArcReader. I want to use ArcMap 10.1 because of the new features, but my operations and engineering staff relies on ArcReader. Or - is there a patch I cannot find? Thanks
... View more
07-30-2013
10:33 AM
|
0
|
0
|
312
|
|
POST
|
Greetings- Having a hard time getting a straight answer on this problem. Does ArcMap 10.1 Service Pack 1 fix the issue with creating a .PMF in ArcMap 10.1 and having the ability to open it in ArcReader 10? I have ArcReader installed on about a dozen machines in my company and will be a pain to go to each one and uninstall 10 and install 10.1 for ArcReader. I want to use ArcMap 10.1 because of the new features, but my operations and engineering staff relies on ArcReader. Or - is there a patch I cannot find? Thanks
... View more
07-30-2013
10:10 AM
|
0
|
2
|
3544
|
|
POST
|
Caleb- You have been a huge help and I appreciate your time in helping me get this process working.... I am a little confused though since I am still very much a rookie when it comes to working with Python scripting. I have the basics down.. but this advanced stuff is a little over my head. My next process: Service Location feature class (the same feature class I have been working with) CIS_Service_Meters Table What do I put where in which script. I have the Memory script in the Python directory. And I will make a new python script for the CIS Service Meters to update into the Service Location feature class ALSO - Do you have a good website tutorial that you can point me to that I can learn about all this advanced python scripting (Dictionaries, indexes, etc)? Thank you
... View more
04-15-2013
09:40 AM
|
0
|
0
|
954
|
|
POST
|
Caleb- At this time - BINGO!!! - Looks like it worked this time. The fields updated. I hope - (1) last question. I have a few other tables/feature classes that I want to be able to do this too.... Specifically dealing with the MemoryTableTools.py that is in the Python directory on my local drive --> For other Tables/Feature Classes - do I add to this python script and just add a inFeatures (Example: inFeatures2)??? Or do I need to make a seperate MemoryTableTools.py for each feature class?? Thanks again That is strange...I use this all the time to update multiple fields and do not have this problem. I am using a slightly different version of the script though since I'm at Arc 10.1, but my version is essentially doing the same thing. I have changed a few parts and simplified the code. Try this:
import sys, traceback, arcpy, os
from os import path as p
def AttributeUpdate(source_table, in_field, update_fields, join_table, join_key, join_values):
# Make sure there is matching number of join and update fields
update_dict = {}
if len(update_fields) == len(join_values):
for i in range(len(update_fields)):
update_dict[join_values] = update_fields
for k,v in update_dict.iteritems():
# Create Dictionary
path_dict = {}
srows = arcpy.SearchCursor(join_table)
for srow in srows:
keyrow = srow.getValue(join_key)
valrow = srow.getValue(k)
path_dict[keyrow] = valrow
del srow, srows
# Update Cursor
urows = arcpy.UpdateCursor(source_table)
for row in urows:
upkey = row.getValue(in_field)
if upkey in path_dict:
row.setValue(v, path_dict[upkey])
urows.updateRow(row)
else:
pass # skip nulls
del row, urows
print '\'%s\' field in "%s" updated successfully' %(v, p.basename(source_table))
else:
print 'ERROR: Number of update fields and value fields does not match'
if __name__ == '__main__':
shp = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\Electric\SERVICE_LOCATION'
dbf = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\CIS_Account_Data'
# Attribute Update
up_fields = ['CUSTOMER_NAME', 'ACCOUNT_NUMBER', 'TWACS_NUMBER', 'ACCOUNT_STATUS']
jn_fields = ['CUSTNAME', 'ACCOUNTNO', 'METERNO', 'ACCOUNT_STATUS_DESC']
AttributeUpdate(shp,'POLE_NUMBER', up_fields, dbf, 'MAPNO', jn_fields)
... View more
04-15-2013
08:59 AM
|
0
|
0
|
954
|
|
POST
|
Caleb- It appears the script is and is not working.... When I run the script in Python IDLE - it shows that it is running and I am not getting errors back... But when I go look at the feature class - the fields are not updated. They are still showing the same data that I had before I ran the script. So it tells me - the script is not updating the field attributes. I can make it work with only (1) field - but when I add additional fields to the list - that is when it does not update. Any ideas??
... View more
04-15-2013
07:27 AM
|
0
|
0
|
954
|
|
POST
|
Chris: Caleb's script is far more advanced than the script I was working on originally with you. At this point the only help I can provide you with is on the original script as I do not have the time to digest and understand Caleb's script. Michael- Not a problem....I am working on doing my homework on your last post dealing with the index(s)
... View more
04-12-2013
09:00 AM
|
0
|
0
|
954
|
|
POST
|
Michael & Caleb- I thought I had the code(s) good to go - but apparently I was wrong and starting to get a little frustrated because I do not understand what I am doing wrong. I can get the code to work just fine BUT with only (1) field at a time. When I add multiple fields to my list in both codes - it does not update anything. Here is the MemoryTableTools.py code:
mport arcpy
from arcpy import env
from MemoryTableTools import *
#Set environment settings
env.workspace = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb"
# Set Local variables
inFeatures = "SERVICE_LOCATION"
joinField = "POLE_NUMBER"
joinField2 = "MAPNO"
joinTable = "CIS_Account_Data"
up_fields = ['CUSTOMER_NAME', 'ACCOUNT_NUMBER', 'TWACS_NUMBER', 'ACCOUNT_STATUS']
jn_fields = ['CUSTNAME', 'ACCOUNTNO', 'METERNO', 'ACCOUNT_STATUS_DESC']
# Run Attribute Update
MemoryTableTools.AttributeUpdate(inFeatures, 'POLE_NUMBER', up_fields, joinTable,'MAPNO',jn_fields)
Here is the other Python script that I am using to run the update:
import sys, traceback, arcpy, os
from os import path as p
def AttributeUpdate(source_table, in_field, update_fields, join_table, join_key, join_values):
try:
""" Updates fields from one table to user defined fields in another table"""
# Check input parameters
if not arcpy.Exists(source_table):
print source_table + ' not found!\nPlease verify that full path of table exists'
sys.exit()
if not arcpy.Exists(join_table):
print join_table + ' not found!\nPlease verify that full path of table exists'
sys.exit()
if in_field not in [f.name for f in arcpy.ListFields(source_table)]:
print in_field + ' not found in ' + p.basename(source_table)
sys.exit()
if join_key not in [f.name for f in arcpy.ListFields(join_table)]:
print join_key + ' not found in ' + p.basename(join_table)
sys.exit()
for fld in update_fields:
if fld not in [f.name for f in arcpy.ListFields(source_table)]:
print fld + ' not found in ' + p.basename(source_table)
print 'Please verify that field names match in ' + p.basename(source_table)
sys.exit()
for fldb in join_values:
if fldb not in [f.name for f in arcpy.ListFields(join_table)]:
print fldb + ' not found in ' + p.basename(join_table)
print 'Please verify that field names match in ' + p.basename(join_table)
sys.exit()
if not type(join_values) == list:
join_values = list(join_values)
if not type(update_fields) == list:
update_fields = list(update_fields)
# Make sure there is matching number of join and update fields
update_dict = {}
if len(update_fields) == len(join_values):
for i in range(len(update_fields)):
update_dict[join_values] = update_fields
for k,v in update_dict.iteritems():
# Create Dictionary
path_dict = {}
srows = arcpy.SearchCursor(join_table)
for srow in srows:
keyrow = srow.getValue(join_key)
valrow = srow.getValue(k)
path_dict[keyrow] = valrow
# Update Cursor
urows = arcpy.UpdateCursor(source_table)
for row in urows:
upkey = row.getValue(in_field)
try:
if upkey in path_dict:
row.setValue(v, path_dict[upkey])
urows.updateRow(row)
except:
pass # skip nulls
print '\'%s\' field in "%s" updated successfully' %(v, p.basename(source_table))
del row, urows, srow, srows
else:
print 'ERROR: Number of update fields and value fields does not match'
except:
print '\nERROR in AttributeUpdate Function.\nPlease Check input parameters and try again.'
if __name__ == '__main__':
shp = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\Electric\SERVICE_LOCATION'
dbf = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\CIS_Account_Data'
# Attribute Update
up_fields = ['CUSTOMER_NAME', 'ACCOUNT_NUMBER', 'TWACS_NUMBER', 'ACCOUNT_STATUS']
jn_fields = ['CUSTNAME', 'ACCOUNTNO', 'METERNO', 'ACCOUNT_STATUS_DESC']
AttributeUpdate(shp,'POLE_NUMBER',up_fields,dbf,'MAPNO',jn_fields)
Can you take a quick look and see what I am doing wrong - why I can get it to work with (1) field but when I add additional fields to it - it will not work at all. Thank you
... View more
04-12-2013
08:25 AM
|
0
|
0
|
954
|
|
POST
|
Michael- Thank you for the update. I am experimenting with Caleb's script to see if I can get it to work properly. I might do some research on the arcpy.AddIndex tool and rework my original script with the Join and Calculate Field tools to see what works best for our environment. Thanks again Chris and Caleb: After further research I think I have found out why my script which performs the same action on a much larger dataset runs quickly. I create an index on the field in the table that I am using to join to the feature class before I create the join. I took the model from another person who built the model in modelbuilder and I exported it to a python script where I made some tweaks (That is why I was unaware of the index previously). As such Chris, you could also add a arcpy.AddIndex_management step to your process in the CIS table which should dramatically speed up your original script (Only if you can not get Caleb's more advanced script to work for you).
... View more
04-12-2013
07:15 AM
|
0
|
0
|
954
|
|
POST
|
Caleb- Yes - some of that makes sense (Use of Dictionaries)... I plan on doing some more research to see if I can use this with other things/ideas with my other geodatabases. I work with electric and water utility infrastructures and been trying to develop some scripts/processes so I can integrate other parts of our company to GIS (CIS data, SCADA, TWACs, ETC). Again..thank you very much.... This is going to cut down ALOT of time in updating my feature classes with tables from our CIS Oracle database Chris @ Chris: I am glad you were able to get it to work. As for having it do more fields you just need to make a list of fields to updated in table A and a list of the fields from table B that contain the values. However, you must make sure to keep the fields in the correct order for each list. For example:
list_A = ['field_1', 'field_2', field_3', etc...] # for table A
list_B = ['field_A', 'field_B', field_C', etc...] # for table B
I have never tested this on more than 7 or so fields at a time but I am sure that it will work the same for 20. Now I will try to explain the dictionary usage: Most of my script is error handling, but the main meat of the script that is actually updating the table is this part:
# Create Dictionary
path_dict = {}
srows = arcpy.SearchCursor(join_table)
for srow in srows:
keyrow = srow.getValue(join_key)
valrow = srow.getValue(k)
path_dict[keyrow] = valrow
# Update Cursor
urows = arcpy.UpdateCursor(source_table)
for row in urows:
upkey = row.getValue(in_field)
try:
if upkey in path_dict:
row.setValue(v, path_dict[upkey])
urows.updateRow(row)
except:
pass # skip nulls
So a dictionary is just made up of pairs consisting of keys and values like this { key : value}. You can look up a value by supplying the key...Values can be any value (even objects and entire lists). The above portion uses a search cursor on table B (with the values) to make a dictionary using each record in the join field (your common field) as a key. The corresponding value will be one of the fields from the "join_fields" parameter. It creates a separate dictionary for each one. Next, an update cursor is used to search through the table and if the value in the join_field in table A is a key in the dictionary, it will update the corresponding "update_field" for that row. I have an exception set up so that it will skip nulls when working through shapefiles. I hope this makes sense. @ Michael I had not tested the field calculator in arcpy land since I upgraded to 10.1. However, after a quick test it seems that it runs much more efficiently now than it did in the past. I have since gotten a new computer so maybe that is why it was so slow in the past. I am glad you find this useful. I have another function from the same script that copies fields from one table to another with the same schema so you can avoid the "field mapping" type operation like in the AttributeUpdate(). I can post that if anyone is interested.
... View more
04-10-2013
11:35 AM
|
0
|
0
|
1097
|
|
POST
|
Caleb and Michael- I got it all to work. The script(s) with the dictionaries did EXACTLY what I wanted it to so with almost NO time at all. Now its just going to take me awhile to program the fields into the script and run an overnight test...... Next step - reading up on dictionaries and indexes so I can attempt to understand this large script that Caleb sent me.. Thank you all (Caleb & Michael) very much for all your help and input.. Think my blood pressure will come down now too...
... View more
04-10-2013
10:31 AM
|
0
|
0
|
1097
|
| 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
|