|
POST
|
Caleb- I got your process/script to WORK.......It took about 15 seconds for the MEMBER_NUMBER field to update from the CIS_Account_data table.... Now - I know I have alot of work to do since I have about 20 fields in my electric model and about 15 in my water model to have this done too... What would be my next step so this works for all of my fields Example: Customer name: Feature Class - CUSTOMER_NAME Table - CUSTNAME Thank you very much!!!!!
... View more
04-10-2013
10:12 AM
|
0
|
0
|
1020
|
|
POST
|
Caleb/Michael- All is correct. What I am doing is simple ArcGIS Python scripting 101.... When it comes to the talk of dictionaries...indexes...etc (Advanced Python scripting) I am lost...... There has to be an easier way for a rookie python scripter like myself to be able to program a process that takes Field "Member Number" from a file Geodatabase table and copy it to a field in a file geodatabase "member number" after it makes a join. Would it be easier: Add Join (Table to Feature Class) - using Map Number/MAPNO as the join attribute Export to a new Feature Class Calculate Field(s) Delete fields that use to be the table Rename feature class back to the original name Is that overkill or would to work??? Caleb: Your solution is very elegant compared to the script that Chris wrote and I helped him modify. I cannot speak for Chris, but your script is advanced and might be difficult for a person new to python scripting. It just seems that Chris' script has a minor issue that can be quickly corrected (once its found) as he is working with such a small dataset.
... View more
04-10-2013
09:41 AM
|
0
|
0
|
1020
|
|
POST
|
Michael- I went to my Feature Class and Table just to verify. The (2) fields I am using to Join the table to the feature class are the same. Also the (2) fields (Member Number) are both [TEXT] field type. Caleb: Is there any reason why Chris' original script should take so long to run? I am working with a much larger feature class and table performing the same type of join and calculate geoprocess and it completes in 5 minutes. Is there any chance it could be due to field type differences between the join field in the table and the field that is being calculated in the feature class?
... View more
04-10-2013
09:24 AM
|
0
|
0
|
1695
|
|
POST
|
Caleb- Went through and did exactly what you said over again with the script you included in the latest E-Mail....And I get this: ImportError: Bad magic number in C:/Python27/ArcGIS10.1/Lib\weakref.pyc Also - when I open the script in Python IDLE - it says version: Python 2.6.5 - is this a big deal or do I need to upgrade? Thanks Hmm, that is strange. Did you save the script as MemoryTableTools.py and put it in your Python folder? I guess you must have since you did not get an import error. Perhaps you could try the namespace then:
import arcpy
from arcpy import env
import MemoryTableTools
# 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 = ['MEMBER_NUMBER']
jn_fields = ['MEMBERNO']
# Run Attribute Update
MemoryTableTools.AttributeUpdate(inFeatures, 'POLE_NUMBER', up_fields, joinTable,'MAPNO',jn_fields)
... View more
04-10-2013
09:22 AM
|
0
|
0
|
1695
|
|
POST
|
Caleb- Its going to take me awhile to figure out the dictionaries and all.... This new script you have me - I did exactly as you directed and get an error message: NameError: name 'AttributeUpdate' is not defined Chris So for your case if you save the script as MemoryTableTools.py like I have, this code should work:
import 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 = ['MEMBER_NUMBER']
jn_fields = ['MEMBERNO']
# Run Attribute Update
AttributeUpdate(inFeatures, 'POLE_NUMBER', up_fields, joinTable,'MAPNO',jn_fields)
Keep in mind that this works on multiple fields at a time if you need to, the above example just works on one field from your first post. Also, be sure to save the script in a path that can be found by python (PYTHONPATH). A directory like this: C:\Python27\ArcGIS10.1\Lib
... View more
04-10-2013
09:04 AM
|
0
|
0
|
1695
|
|
POST
|
Chris: When is the feature class being saved to disk, as I do not see this in your code sample? arcpy.CalculateField_management(layerName, "SERVICE_LOCATION.MEMBER_NUMBER", '!MEMBERNO!', "PYTHON") This appears to be incorrect as layerName should be the in_table expression should be !CIS_Account_Data.MEMBERNO! as you need to explicitly specify that this is coming from a join field. No Dice.... I am working with just this (1) field and after waiting 20 minutes - it does not complete. Is is possible this temp feature layer is causing issues??
... View more
04-10-2013
08:09 AM
|
0
|
0
|
1156
|
|
POST
|
Hi, I had the same problem with AddJoin + CalculateField efficiency. One solution could be creating indexes on fields you're using in join if you hadn't done this before. If this won't help (sometimes it's not enough) I would suggest using combination of arcpy.sa.SearchCursor and python dictionary to collect right data from table, and then arcpy.da.UpdateCursor to update featureclass fields. It take some time to write, but it's very efficient. If you need some details feel free to ask. Best Regards. Arek Arek- Thank you for the reply. Creating the Feature Layer and doing the Join seems to work just fine without any hold-up or lagging.... This is being done outside of ArcMap outside of an Edit Session... My intention is to have this done automatically at night and the only way I have figured out to do it is to have a Python Script and run a schedule task using the Windows Task Scheduler. Forgive me - but I am still really new to Python and not sure how to use or write indexes and python dictionaries......I have done some (very little reading on it)..... Any ideas???? Thank you
... View more
04-10-2013
08:06 AM
|
0
|
0
|
1695
|
|
POST
|
I need help really bad. I have been looking through all of the Forum posts and and Help sections to try to figure out what is wrong with no luck. Here is what I am doing: I have a File Geodatabase (ArcMap 10.0) with a Feature Class (Service Location) which is the physical location of our electric meters. I have multiple fields that I need to update on a nightly basis. This data comes from our CIS system which holds account, customer and meter attribute information. I have a script to runs automatically every night that pulls an Oracle VW through an ODBC connection and brings it into my File Geodatabase as a Geodatabase Table. What I have to do is to update a specific field (Account Number) in the Feature Class with the same field in the table (ACCOUNTNUM)... Just an example. What I want to be able to do is to also have this script run automatically at night. I have around 9500 records in the feature class with about 15 different fields to do this to. The problem I am having is it takes up to 20 to 25 minutes for each field to update so at times - the script can take 8 to 9 hours to complete. From what I understand - this should take only a few minutes.... So what I am doing is not working. I decided to go back to the "Drawing Board" to see if there is something I am missing with writing the code..... I decided to work with (1) field right now to see if I can make it work and get the update time down before I rewrite the rest of the code. This is what I currently have and it does not seem to be working: ## Set the necessary product code import logging # Import arcpy module import arcpy from arcpy import env # if run in ArcGIS Desktop, show messages, also print to log def log(method, msg): print msg method(msg) logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)-s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='Test_Update.log', filemode='w' ) log(logging.info, "Updating Service Locations Feature Class Begins") # Set environment settings env.workspace = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb" # Set Local variables: inFeatures = "SERVICE_LOCATION" # Service Location Feature Class layerName = "SERVICE_LOCATION_LAYER" # Service Location Feature Layer fieldName1 = "SERVICE_ADDRESS" expression1 = "CIS_Account_Data.SERVICE_ADDRESS" joinField = "POLE_NUMBER" joinField2 = "MAPNO" joinTable = "CIS_Account_Data" # Create a Feature Layer from Service_Location Feature Class log(logging.info, "Create Feature Layer for Service Location Feature Class") arcpy.MakeFeatureLayer_management(inFeatures, layerName) # Join the feature layer to a table log(logging.info, "Join Table to Feature Layer Service Location") arcpy.AddJoin_management(layerName, joinField, joinTable, joinField2) # Process: Calculate Field (Member Number) log(logging.info, "Update Member Number Field") arcpy.CalculateField_management(layerName, "SERVICE_LOCATION.MEMBER_NUMBER", '!MEMBERNO!', "PYTHON") log(logging.info, "Complete") I am not sure what is slowing this down. Am I looking at this process the wrong way?? Are there different tools that can be used to complete this mission?? Thank you for your help
... View more
04-10-2013
07:42 AM
|
0
|
33
|
4641
|
|
POST
|
Here is the current updated Python script that I have. I tried to run the script through Python IDLE and just running it by double-clicking on the file which brings up DOS... and it still seems to lag and lag. I will post this on the Python form and see if someone else can think of something. ## Set the necessary product code
import logging
# Import arcpy module
import arcpy
from arcpy import env
# if run in ArcGIS Desktop, show messages, also print to log
def log(method, msg):
print msg
method(msg)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)-s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='ServiceLocation_CISAccountData_Updates.log',
filemode='w'
)
log(logging.info, "Updating Service Locations Feature Class Begins")
# Set environment settings
env.workspace = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb"
# Set Local variables:
inFeatures = "SERVICE_LOCATION" # Service Location Feature Class
layerName = "SERVICE_LOCATION_LAYER" # Service Location Feature Layer
fieldName1 = "SERVICE_ADDRESS"
expression1 = "CIS_Account_Data.SERVICE_ADDRESS"
joinField = "POLE_NUMBER"
joinField2 = "MAPNO"
joinTable = "CIS_Account_Data"
# Create a Feature Layer from Service_Location Feature Class
log(logging.info, "Create Feature Layer for Service Location Feature Class")
arcpy.MakeFeatureLayer_management(inFeatures, layerName)
# Join the feature layer to a table
log(logging.info, "Join Table to Feature Layer Service Location")
arcpy.AddJoin_management(layerName, joinField, joinTable, joinField2)
# Process: Calculate Field (Member Number)
log(logging.info, "Update Member Number Field")
arcpy.CalculateField_management(layerName, "SERVICE_LOCATION.MEMBER_NUMBER", '!MEMBERNO!', "PYTHON")
log(logging.info, "Complete")
... View more
04-10-2013
07:27 AM
|
0
|
0
|
1156
|
|
POST
|
Chris: Here is a code snippet where I use python syntax instead of VB syntax: arcpy.CalculateField_management(rdcl_Layer, "MUNI_NUM_RIGHT_UNPAD", '!MUNI_NUM_RIGHT!.lstrip("0")', "PYTHON", "") For your code: arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MEMBER_NUMBER", "[CIS_Account_Data.MEMBERNO]", "VB", "") change it to arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MEMBER_NUMBER", '!CIS_Account_Data.MEMBERNO!', "PYTHON", "") I would even set the env variable as the destination file geodatabase so you do not need to reference it in your call to CalculateField_management Near the top of your script below import arcpy from arcpy import env env.workspace = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb\\CIS_Account_Data" then your code could be arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MEMBER_NUMBER", '!MEMBERNO!', "PYTHON", "") I'm not really sure this is the issue as I use VB notation in a CalculateField_management process where I have 200,000 records and it only takes 5 minutes as opposed to hours. Michael- That helps out alot...I am not getting any error messages so I wrote the code correctly with your help. But that still does not solve my problem. It seems to be freezing or not finishing when I run the calculate field tool. The Geodatabase and all of the data is on my Local drive instead of being ran over the network. Also - I am running the Python script with Python IDLE 2.6.5. Do you think that might be a reason why it is taking so long to run?? You have been a great help in working with me on the code. I am not sure if its the Geodatabase or the version of Python I am using or something else. I am only updating 9000 records and working with (1) field right now. Anything else you can possibly think of that I am doing wrong???
... View more
04-10-2013
07:00 AM
|
0
|
0
|
1156
|
|
POST
|
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MEMBER_NUMBER", "[CIS_Account_Data.MEMBERNO]", "VB", "") Chris: Maybe because you are using the VB syntax it is taking a long time for the CalculateField_management process. Try converting this to PYTHON with the appropriate syntax for field names [field name] as per the documentation. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000 How exactly would I write that? I am still trying to figure out Python
... View more
04-09-2013
01:56 PM
|
0
|
0
|
1156
|
|
POST
|
I'm curious on one thing - is doing the "Make Feature Layer" and "Add Join" have anything to do with the long time it takes to do the "Calculate Field" tool outside of an edit session?? Chris - Can you just run the "Make Feature Layer" and "Add Join" part of your python script and see how long it takes? This could determine that this is the cause of the long processing time? I would even just run the "Make Feature Layer" separately from the "Add Join" to determine which process is causing the long processing time. I went through and just did the "Make Feature Layer" and "Add Join" tool on its own and it was done within 10 seconds. For some reason - the calculate field tool takes a long time??? Not sure how to speed it up or if there is another tool that works the same way?? Is it a problem that I am trying to "Override" (E) values/data inside the field? Would it make any difference if the field was blank??
... View more
04-09-2013
10:00 AM
|
0
|
0
|
1156
|
|
POST
|
Chris: Can you try running the script on just 1 field and see how long it takes. Then try running the script on 1 other field and see how long that takes. Then run the script on those two fields and see if it runs as long as running the 2 fields in individual scripts? I'm just curious if the CalculateField_management process runs much longer on the 2nd field when run in series. I'm curious on one thing - is doing the "Make Feature Layer" and "Add Join" have anything to do with the long time it takes to do the "Calculate Field" tool outside of an edit session?? I know there has to be an easier/faster way of taking data from a Geodatabase table and put it into a Geodatabase Feature Class.... I did the (1) field like you suggested and I did (2) fields in the same script and it did not seem to make a difference.....
... View more
04-09-2013
08:52 AM
|
0
|
0
|
1522
|
|
POST
|
mvolz47;287670 wrote: When you are posting your reply go to the Code wrap menu and select # (It is in the 2nd row to the right above the posting window). Put CODE (with brackets) at the beginning of your code and /CODE (with brackets) at the end of your code as shown in my below sample that does not do anything but provide a visual sample. #
# Set the necessary product code
import logging
# Import arcpy module
import arcpy
# if run in ArcGIS Desktop, show messages, also print to log
def log(method, msg):
print msg
method(msg)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)-s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='ServiceLocationsAttributes_Updates.log',
filemode='w'
)
log(logging.info, "Updating Service Locations Feature Class Begins")
# Local variables:
SERVICE_LOCATION = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb\\Electric\\SERVICE_LOCATION"
CIS_Account_Data = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb\\CIS_Account_Data"
CIS_Service_Meters = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb\\CIS_Service_Meters"
SERVICE_LOCATION_FL = "SERVICE_LOCATION_FL"
SERVICE_LOCATION_FL__2_ = "SERVICE_LOCATION_FL"
SERVICE_LOCATION_FL__24_ = "SERVICE_LOCATION_FL"
# Process: Make Feature Layer of Service Location FC
log(logging.info, "Create Feature Layer for Service Location Feature Class")
arcpy.MakeFeatureLayer_management(SERVICE_LOCATION, SERVICE_LOCATION_FL, "", "", "SUBTYPE SUBTYPE VISIBLE NONE;PHASE PHASE VISIBLE NONE;OH_UG OH_UG VISIBLE NONE;FLOW FLOW VISIBLE NONE;PROTECTION_DEVICE PROTECTION_DEVICE VISIBLE NONE;CIS_SERVICE_ID CIS_SERVICE_ID VISIBLE NONE;TRANSFORMER_BANK_ID TRANSFORMER_BANK_ID VISIBLE NONE;POLE_NUMBER POLE_NUMBER VISIBLE NONE;LINE_AND_POLE LINE_AND_POLE VISIBLE NONE;LOCATION_TAG LOCATION_TAG VISIBLE NONE;CIRCUIT_ID CIRCUIT_ID VISIBLE NONE;CIRCUIT_SOURCE CIRCUIT_SOURCE VISIBLE NONE;ASSEMBLY_CODE ASSEMBLY_CODE VISIBLE NONE;DESIGN_STATE DESIGN_STATE VISIBLE NONE;COMMENTS COMMENTS VISIBLE NONE;LABEL_TEXT LABEL_TEXT VISIBLE NONE;LOT_NUMBER LOT_NUMBER VISIBLE NONE;EASEMENT EASEMENT VISIBLE NONE;ATS_DIRTY ATS_DIRTY VISIBLE NONE;DTS_CREATED DTS_CREATED VISIBLE NONE;DTS_CHANGED DTS_CHANGED VISIBLE NONE;CHANGED_BY CHANGED_BY VISIBLE NONE;ATS_GUID ATS_GUID VISIBLE NONE;LOCATION_OID LOCATION_OID VISIBLE NONE;SYMBOL_ROTATION SYMBOL_ROTATION VISIBLE NONE;ANCILLARYROLE ANCILLARYROLE VISIBLE NONE;ENABLED ENABLED VISIBLE NONE;OLD_LOCATION OLD_LOCATION VISIBLE NONE;TRANSFORMER_MAPNO TRANSFORMER_MAPNO VISIBLE NONE;TRUCK_NUMBER TRUCK_NUMBER VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;OBJECTID OBJECTID VISIBLE NONE;METER_TYPE_ID METER_TYPE_ID VISIBLE NONE;METER_PACK_OID METER_PACK_OID VISIBLE NONE;METER_SOCKET METER_SOCKET VISIBLE NONE;SERVICE_ADDRESS SERVICE_ADDRESS VISIBLE NONE;LOC_TYPE LOC_TYPE VISIBLE NONE;SERVICE_TYPE SERVICE_TYPE VISIBLE NONE;MEMBER_NUMBER MEMBER_NUMBER VISIBLE NONE;CUSTOMER_NAME CUSTOMER_NAME VISIBLE NONE;MAIL_ADDRESS MAIL_ADDRESS VISIBLE NONE;MAIL_CITY MAIL_CITY VISIBLE NONE;MAIL_STATE MAIL_STATE VISIBLE NONE;MAIL_ZIP MAIL_ZIP VISIBLE NONE;ACCOUNT_NUMBER ACCOUNT_NUMBER VISIBLE NONE;TWACS_NUMBER TWACS_NUMBER VISIBLE NONE;METER_TYPE METER_TYPE VISIBLE NONE;METER_BOOK METER_BOOK VISIBLE NONE;BILLING_CYCLE BILLING_CYCLE VISIBLE NONE;PHONE PHONE VISIBLE NONE;PHONE_TYPE PHONE_TYPE VISIBLE NONE;ACCOUNT_STATUS ACCOUNT_STATUS VISIBLE NONE;RATE_CODE RATE_CODE VISIBLE NONE;MULTIPLIER MULTIPLIER VISIBLE NONE;READ_DATE READ_DATE VISIBLE NONE;BILLED_DATE BILLED_DATE VISIBLE NONE;DISCONNECT_DATE DISCONNECT_DATE VISIBLE NONE;CIS_EXPORT_DATE CIS_EXPORT_DATE VISIBLE NONE;DIAL_STYLE DIAL_STYLE VISIBLE NONE;KSUBH KSUBH VISIBLE NONE;FORM FORM VISIBLE NONE;METER_AMPS METER_AMPS VISIBLE NONE;METER_WIRES METER_WIRES VISIBLE NONE;METER_VOLTS METER_VOLTS VISIBLE NONE;METER_CLASS METER_CLASS VISIBLE NONE;METER_TYPE_DESC METER_TYPE_DESC VISIBLE NONE;MANUFACTURER MANUFACTURER VISIBLE NONE;SERVICE_ADD_NOTE SERVICE_ADD_NOTE VISIBLE NONE;AMPS AMPS VISIBLE NONE;SOCKET_CONDITION SOCKET_CONDITION VISIBLE NONE;POINT_X POINT_X VISIBLE NONE;POINT_Y POINT_Y VISIBLE NONE;MEWCo_MAP_GRID MEWCo_MAP_GRID VISIBLE NONE")
# Process: Add Join (CIS Account Data Table)
log(logging.info, "Add CIS_Account_Data Table to Feature Layer")
arcpy.AddJoin_management(SERVICE_LOCATION_FL, "POLE_NUMBER", CIS_Account_Data, "MAPNO", "KEEP_ALL")
# Process: Calculate Field (Member Number)
log(logging.info, "Update Member Number Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MEMBER_NUMBER", "[CIS_Account_Data.MEMBERNO]", "VB", "")
# Process: Calculate Field (Customer Name)
log(logging.info, "Update Customer Name Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.CUSTOMER_NAME", "[CIS_Account_Data.CUSTNAME]", "VB", "")
# Process: Calculate Field (Mailing Address)
log(logging.info, "Update Mail Address Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MAIL_ADDRESS", "[CIS_Account_Data.MAIL_ADDRESS]", "VB", "")
# Process: Calculate Field (Mail City)
log(logging.info, "Update Mail City Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MAIL_CITY", "[CIS_Account_Data.MAIL_CITY]", "VB", "")
# Process: Calculate Field (Mail State)
log(logging.info, "Update Mail State Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MAIL_STATE", "[CIS_Account_Data.MAIL_STATE]", "VB", "")
# Process: Calculate Field (Mail Zip)
log(logging.info, "Update Mail Zip Field")
arcpy.CalculateField_management(SERVICE_LOCATION_FL__2_, "SERVICE_LOCATION.MAIL_ZIP", "[CIS_Account_Data.ZIP]", "VB", "")
Here is a clip of the code
... View more
04-08-2013
09:26 AM
|
0
|
0
|
1522
|
|
POST
|
Can you provide the python script that you are running? Please put it in the appropriate code block syntax so it is indented correctly. How exactly do I add the Python Script to the text window here so you can see it the way you are requesting??
... View more
04-08-2013
08:45 AM
|
0
|
0
|
1522
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 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 |
2 weeks ago
|