POST
|
This will always be painfully slow as you are performing many operations inside each iteration of each row inside your update cursor. Also, using nested cursors is generally a bad idea. I think there has to be a better way to do this. I am not quite sure I completely follow what you are doing here but I think I have an idea. I would suggest instead of this process, do a spatial join of your ZoneValves to the Mains and store this in the in_memory workspace. Next, I would iterate through this in_memory table and build a dictionary using the 'JOIN_FID' and the 'COUNT'. You could then call your update cursor and if use the dictionary to update the table. I think this process would be much faster. Is there any chance you could post a small sample of your data? Hello Caleb, This is an excellent idea! I unfortunately cannot post our data on a public forum as that would violate our security rules, however I understand the process you described so I will give that a try. I knew there had to be a better way than using nested cursors 🙂 Thank you very much for the suggestion!
... View more
06-08-2013
09:13 AM
|
0
|
0
|
130
|
POST
|
We are trying to accomplish the following: 1. Water Mains have a Pressure Zone assigned to them depending on what zone they are located in. 2. The junction/point features (valves, fittings, etc.) have attributes called PRESSUREZONE1 and PRESSUREZONE2. 3. The Pressure Zone values of the mains connected to the junction determine what its PRESSUREZONE1/2 values are. If all the mains connected have the same Pressure Zone value, then PRESSUREZONE1 is that value and PRESSUREZONE2 is Null. If the mains have two or more values, PRESSUREZONE1 is one value, and PRESSUREZONE2 is one of the other values (there are no specific criteria for what to do if there are 3 ore more different Pressure Zones, and there is not a field to hold the extra values anyway. I have started a script to assign the PRESSUREZONE1/2 values to the junctions programmatically, and am just testing it with two featureclasses so far: ZoneValves and Mains. The script does work, but it is very slow and takes about 1-second per feature to process. This is a big problem as some of the junction featureclasses have tens of thousands of records. Here is what I have done so far:
# Import arcpy module
import arcpy, string
# Local variables:
Main = "Database Connections\\gissde.sde\\CITY.Water\\CITY.Main"
ZoneValve = "Database Connections\\gissde.sde\\CITY.Water\\CITY.ZoneValve"
arcpy.MakeFeatureLayer_management(Main, "Main_Lyr")
arcpy.MakeFeatureLayer_management(ZoneValve, "ZoneValve_Lyr")
rows = arcpy.UpdateCursor("ZoneValve_Lyr")
for row in rows:
arcpy.SelectLayerByAttribute_management("ZoneValve_Lyr", "NEW_SELECTION", "AW_ID = " + str(row.AW_ID))
arcpy.SelectLayerByLocation_management("Main_Lyr", "INTERSECT", "ZoneValve_Lyr", "", "NEW_SELECTION")
mainPZList = []
mainRows = arcpy.SearchCursor("Main_Lyr")
for mainRow in mainRows:
mainPZList.append(mainRow.PRESSUREZONE)
mainPZList = list(set(mainPZList)) # Remove duplicate values from list
if len(mainPZList) >= 1:
row.PRESSUREZONE1 = mainPZList[0]
rows.updateRow(row)
if len(mainPZList) > 1:
row.PRESSUREZONE2 = mainPZList[1]
rows.updateRow(row)
Basically I am making feature layers out of the featureclasses, creating an Update Cursor to iterate through the junction/point features, then for each feature doing a spatial selection to select the mains that intersect the junction, adding the pressure zones for those mains to a list, using "set" to compress the list to remove duplicate values, then populating the PRESSUREZONE1/2 values of the junction feature based on whether or not one or more Pressure Zone values are found in the list of connected mains. I see some obvious problems, such as creating a Search Cursor for each junction (tens of thousands of search cursors are created when this is run), however I'm not sure of a faster, more efficient way to do this. If you guys have any suggestions I would appreciate them very much!
... View more
06-07-2013
01:41 PM
|
0
|
2
|
632
|
POST
|
So, I've basically gotten this working (not to the finished script yet, though). I'm using search cursors to build dictionaries of the feature classes, only providing an ID field and a modified date field (which is used to key off of for Updates). I compare the dictionaries and anything that is in the source featureclass, but not the target, is added to a list of "adds". Anything that is in the target feature class, but not in the source, is added to a list of "deletes". Anything that is in both feature classes but has a different "modified date" is added to a list of "updates". I am then using insert/update cursors to iterate through the rows of the feature classes, and making edits where appropriate until they have identical data. I'll post the finalized script later once it is ready.
... View more
04-08-2013
01:49 PM
|
0
|
0
|
235
|
POST
|
Many thanks to both of you for your help. I see what you mean about overwriting a row with itself. That was a typo on my part as I was trying to change the names of the variables to be more generic/readable in the post, so my apologies on that. The actual script was trying to read the row from the other cursor: targetFCCur.updateRow(sourceFCRow) Raphael, thank you for the example you posted. One question: what can I do to retain the shape information since it cannot be included in the dictionary? All the other fields will need to be copied, but the shape will also need to be transferred. At the moment, I've decided to just delete the existing record and insert the updated record instead. It's not ideal, but it is working ok if nothing else works.
... View more
04-08-2013
01:35 PM
|
0
|
0
|
563
|
POST
|
I am trying to update an SDE feature class based on another SDE feature class using an Update Cursor. Th feature classes have identical fields and the same number of records. There is a "LASTMODIFIED" date field that is changed anytime a record is updated in the source feature class. What I'm doing is matching up the rows in each table using their "ID" field, then checking to see if the "LASTMODIFIED" date is different. If it is different, then I want to update the entire row of the target feature class with the row from the source feature class. For some reason, this is not working. The script runs without error, and I've inserted counters to make sure it is finding cases where the last modified dates are different (it is). However, when I check the records of the target dataset after the script has run, no data has been changed at all. Does anyone know why this is happening? I want the entire record to be replaced with the source FCC record, and I thought updateRow() would do that. The only other thing I can think of is to delete the existing record and insert the record I want in its place, but that seems kind of stupid to me. sourceFCCur = arcpy.UpdateCursor(SourceFCPath) for sourceFCRow in sourceFCCur: targetFCCur = arcpy.UpdateCursor(TargetFCPath) for targetFCRow in targetFCCur: if targetFCRow.ID == sourceFCRow.ID: sourceFCDate = sourceFCRow.getValue('LASTMODIFIED') targetFCDate = targetFCRow.getValue('LASTMODIFIED') if sourceFCDate != targetFCDate: targetFCCur.updateRow(targetFCRow) del targetFCCur
... View more
04-07-2013
11:04 AM
|
0
|
5
|
2363
|
POST
|
Ok, well I think I've figured out what to do, but I don't know how yet: 1. To search for differences between the feature classes and then find what features have been added, modified or deleted: SearchCursor 2. To update features in the target feature class that have been updated in the source feature class: UpdateCursor 3. To delete features in the target feature class that have been deleted from the source feature class: UpdateCursor 4. To add features to the target feature class that have been deleted from the source feature class: InsertCursor Now I have to figure out how to actually compare the feature classes, store the differences somewhere, then read from the differences and update the target feature class accordingly. Since I am basically just making edits, I don't have to worry about whether or not the feature class is being accessed (read-only, so it will only be viewed while I am making the edits; it won't be edited by anyone else).
... View more
04-05-2013
07:07 PM
|
0
|
0
|
235
|
POST
|
We need to replicate data from SDE 10.0 to SDE 9.2, which is not possible using replicas due to all the changes between versions 9.2 and 10. I know of at least one case where someone is doing this very thing using Python, but I unfortunately do not have access to their script and have no idea how they're doing it. Basically, they are copying a featureclass from SDE 10 to SDE 9.2, while SDE 9.2 is running and also while that featureclass is being accessed in the 9.2 SDE. I have tried a few options to do this and always run into locks on the 9.2 featureclass since it is currently in use by other users/applications. We pretty much need to do what a replica does: synchronize changes (adds/deletes/modifications) in the featureclass between the two databases without having to stop the database or block access to the featureclass. How would you go about accomplishing this in Python? I have searched through the geoprocessing documentation and simply cannot figure out how to do this. All of my searches lead back to replication, but again, creating a replica that will move data from SDE 10 to SDE 9.2 is not possible. Any and all ideas would be most appreciated!
... View more
04-05-2013
01:17 PM
|
0
|
3
|
357
|
POST
|
I have looked all over ESRI's site and have not found a straight answer to this question: Can a service that sits behind a company's firewall be published to ArcGIS Online? I was under the impression that there was a way to do this, either with ArcGIS Online or Portal for ArcGIS. Basically, we don't want to expose the service to the public, but we do want to add it to web maps that can be accessed outside of our firewall by people in the field using smart phones and/or tablets running the ArcGIS app. Since the phones/tablets will be accessing the internet through the cellular network, there isn't a way to have them connect directly into our intranet. Given this, we would just control access to the actual application by user accounts. Is this possible to do? Do we have to choose one or the other? We're not really interested in having to copy our data to ArcGIS Online regularly, but we also can't make the map service we want to use available to the public either.
... View more
03-01-2013
11:44 AM
|
0
|
3
|
478
|
POST
|
Hi Jake, Thank you very much for the link! We are running Oracle here, but I will see if I can modify the script to work for us. Cheers 🙂
... View more
05-11-2012
01:58 PM
|
0
|
0
|
248
|
POST
|
Does anyone have an example of how to kill specific SDE connections using a batch file? Basically, I manually kill certain connections throughout the day to keep our server from maxing out during peak hours. The connections are searched by username: sdemon -o info -I users -i esri_sde2 | find "username" Then killed: sdemon -o kill -i esri_sde2 -N -p password -t <S-ID> I have used batch files for various things in the past, but this particular one is challenging. I was reading about using delimiters to find particular parts of a string, etc. and my head almost exploded. Does anyone have an example that I could use to get started? Thanks 🙂
... View more
05-10-2012
06:46 AM
|
0
|
2
|
876
|
POST
|
Thank you very much for your help! I will install SP4 and see if that fixes the crashes.
... View more
04-11-2012
01:47 PM
|
0
|
0
|
279
|
POST
|
We recently upgraded from ArcGIS 9.3.1 to 10. In ArcMap, when I am editing features, I've noticed on the attribute window that some of the fields are showing up in light green. On those fields, the values are not in a drop down combo box like they were in all the previous versions, instead there is a button with three "dots" on it, and I have to click that to then select a value. This is only on certain fields, and a few times when I've selected a value ArcMap will subsequently crash. What is going on here? Does it have something to do with the layer files? Do they work differently in 10 than they did in 8.x-9.x? I have included some screenshots that illustrate what I am talking about. You can see the "green" fields in the attribute window, and you can see how I get the "button" in one of those fields, but the regular drop-down in the field right below it. If you have any suggestions why this is happening and what I need to do to fix it, I would appreciate it very much. [ATTACH=CONFIG]13425[/ATTACH]
... View more
04-11-2012
12:03 PM
|
0
|
2
|
869
|
POST
|
Hello Michael, Thank you so much for your reply. I am not calling the script from a batch file, but maybe that is how I should do it. Could you maybe post an example of how to do this in Server 2008? Also, I spoke too soon about the automatically-generated email as it is not working at all. However, that may just be something I need to work with our Exchange administrator to resolve. I had actually found an example online to run a Python script as a Windows service and I may still end up going that route. Apparently there are a lot of people out there who are frustrated with the clunkiness of the task scheduler in Server 2008.
... View more
03-01-2012
07:24 AM
|
0
|
0
|
1182
|
POST
|
I have setup a python script to run as a scheduled task on a server running Windows Server 2008 (which was ridiculously hard to do in itself). I can run the task manually and it does what it is supposed to do (export a bunch of Data Driven Pages as .pdfs), however it is *not* doing two of the things it is supposed to: 1. Open a console window while it's running, 2. Send an automated email when it is done. Now, if I just manually double-click on the script itself and run it, the command window opens and the email is sent without any issues. Why does it not do these things when run as a scheduled task? Is there some sort of setting that I need to change? I'm finding scheduled tasks in Server 2008 to be very painful to try to use. I have none of these problems when running the script as a scheduled task in Server 2003.
... View more
02-29-2012
07:02 PM
|
0
|
17
|
2999
|
Title | Kudos | Posted |
---|---|---|
2 | 01-23-2012 11:44 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|