|
POST
|
Change this: with arcpy.da.UpdateCursor("QueryTable", ["SHAPE", "leakage_with_pon_list_Eastings", "leakage_with_pon_list_Northings", "leakage_with_pon_list_RandomNumber"]) as cursor:
or to this: flds = ["SHAPE", "leakage_with_pon_list_Eastings", "leakage_with_pon_list_Northings", "leakage_with_pon_list_RandomNumber"]
with arcpy.da.UpdateCursor("QueryTable", flds) as cursor:
(Edits applied above)
... View more
01-28-2015
08:40 AM
|
0
|
2
|
2313
|
|
POST
|
Yes, you're correct I would like to insert rows, but if possible I would like to just update / delete the existing rows where the IDs match to improve efficiency / performance. You are wanting to handle a transactional process with a scripting language. Depending on frequency of the updates/inserts would likely drive my approach. If it's an interactive/dynamic requirement then I'd develop an application tier to help manage it (ADO.NET would be my first choice, along with StoredProcedures on the SQL database). This Storm Water Revenue Management System | ArcNews is a good example. An alternative might be a simple TRUNCATE and then BULK INSERT containted in a StoredProcedure would likely suffice but I have no idea data size you are working with. This table could participate in a join or spatial view and presented to the user. Sorry I don't have a python recommendation and hope someone has a better solution for you.
... View more
01-26-2015
05:21 AM
|
0
|
0
|
3829
|
|
POST
|
I don't see what the issue is and why you need to join anything. According to your OP you just need to insert new rows into the GDB table. Aside from that, perhaps it has something to do with naming everything the same? FH_Tickets_Table_Out = "\\in_memory\\FireHydrant_Tickets"
FH_Join_Output = "\\in_memory\\FireHydrant_Tickets"
FH_Delete_Matches = "\\in_memory\\FireHydrant_Tickets"
FH_Tickets_CSV_Join_Out = "\\in_memory\\FireHydrant_Tickets" I really don't know and not able to follow along your code well enough to understand your process logic.
... View more
01-23-2015
05:16 AM
|
0
|
4
|
3829
|
|
POST
|
Currently all of the rows are deleted and an updated CSV file is appended to the GIS table, basically a wipe and replace Make this easy for forum members to help you by posting up the current code you have. This will give us something to go on and an initial view of your process needs. If this is just done manually, then spell out the steps you use. There are some considerations when attempting to update RDMS tables that participate in ArcSDE instance and you need to be aware of these potential issues before deciding on a path to take.
... View more
01-22-2015
05:02 AM
|
0
|
0
|
3829
|
|
POST
|
I just figured out that the function came across an empty tuple and then crashed. Apparently select by attribute can't deal with an empty tuple in the argument, I assumed it would just skip it. Oops. This is likely not going to be your only issue. Depending upon what RDBMS you are working with will also have an affect on your "IN" clause because each one has their own limits to the number of values allowed in the SQL statement. One solution is to cycle thru a pre-set number of values (say up to 1000 "U_ID" values attempting to be passed into the sql statement). If it exceeds that limit then use an alternate "arcpy.SelectLayerByAttribute_management" with the "ADD_TO_SELECTION" property assigned, if less than the 1000 limit then just keep the "NEW_SELECTION" property assigned. Another option is to create in_memory table of the selected "U_ID" values, join this back to your feature class and then select on values NOT NULL in the join fields. Sorry no code to post up.
... View more
01-21-2015
05:39 AM
|
0
|
0
|
2000
|
|
POST
|
http://resources.arcgis.com/en/help/main/10.1/index.html#//001500000006000000http://
... View more
01-14-2015
11:43 AM
|
1
|
0
|
3070
|
|
POST
|
Create a new geoprocessing tool, set the source to your .py file, add the tool to your model.
... View more
01-14-2015
11:12 AM
|
0
|
2
|
3070
|
|
POST
|
The above code is run in Visual Studio What project type in VS allows you run python code? Or are you executing a .bat file from the application you developed in Visual Studio (there's lots of different types of apps you can develop, VS is just the IDE).
... View more
01-14-2015
11:10 AM
|
0
|
0
|
1320
|
|
POST
|
Your variable needs to be like this in your expression: Gwich''in Do you see the two (2) apostrophe's? That's how it must be set. How you deal with setting a variable will be up to you because you will need to check to see an apostrophe exists and if so then double it up. I cannot understand the code you posted.
... View more
01-14-2015
05:36 AM
|
0
|
1
|
892
|
|
POST
|
I just setup an example scenario that fits the OP's issue of attempting to build a query expression that must pickup string values stored with apostrophe's in them. The sample FeatureClass just has 2 features/rows and I populated a field called "strtest" with a string value: "Gwich'in" just like the OP has. Then I just setup a da.SearchCursor to test out how to overcome the limitations of building an expression to include the apostrophe: txt = """'Gwich''in'"""
fc = r'H:\Documents\ArcGIS\Default.gdb\TestLayer'
flds = ['OBJECTID','strtest']
sql = """strtest = """ + txt
print sql
with arcpy.da.SearchCursor(fc, flds, sql) as cur:
for row in cur:
print("{0}, {1}".format(row[0], row[1]))
sys.exit() By simply adding an extra apostrophe in the expression, it successfully selects the feature/row.
... View more
01-13-2015
01:19 PM
|
0
|
3
|
2572
|
|
POST
|
In your expression try adding an extra ' apostrophe to the string. For example: expression = """MyField = 'Gwich''in'""" That is instead of Gwich'in add an extra apostrophe between the "h" and "I" characters: Gwich''in
... View more
01-13-2015
12:11 PM
|
0
|
7
|
2572
|
|
POST
|
Can you remove the single apostrophe from the source data? If not, can you replace it with the GRAVE ACCENT or Backtick "`"? I am unsure about ISO sql standards as it relates to the character, but it does work in a da.SearchCursor as long as it is acceptable to replace the apostrophe in the data.
... View more
01-13-2015
10:21 AM
|
0
|
9
|
2572
|
|
POST
|
I know there's no interest in pandas, but it really simplifies things and supercharges performance. This along with the arcpy.da.TableToNumpyArrray method it makes it super easy to integrate. Test data (I just created a .csv file but it could be a gdb table or just about anything else): BLDG_ID,HAZARD_ID,OTHER FIELDS 37013,11,other info unique to HAZ_ID 11 37013,46,other info unique to HAZ_ID 46 37013,9,other info unique to HAZ_ID 9 37013,16,other info unique to HAZ_ID 16 37013,17,other info unique to HAZ_ID 17 37013,18,other info unique to HAZ_ID 18 37014,8,other info unique to HAZ_ID 8 37014,6,other info unique to HAZ_ID 6 37014,33,other info unique to HAZ_ID 33 37014,16,other info unique to HAZ_ID 16 37014,17,other info unique to HAZ_ID 17 37014,18,other info unique to HAZ_ID 18 This does exactly what you want OP: dat = r"H:\pandas_testdat.csv"
df = pd.read_csv(dat)
df2 = df[df['HAZARD_ID'].isin([16,17,18])]
print df2.values Yeah. That's all that is necessary Result: BLDG_ID,HAZARD_ID,OTHER FIELDS 37013L 16L 'other info unique to HAZ_ID 16' 37013L 17L 'other info unique to HAZ_ID 17' 37013L 18L 'other info unique to HAZ_ID 18' 37014L 16L 'other info unique to HAZ_ID 16' 37014L 17L 'other info unique to HAZ_ID 17' 37014L 18L 'other info unique to HAZ_ID 18'
... View more
01-09-2015
05:41 AM
|
0
|
0
|
1370
|
|
POST
|
No problem. I was just working thru grouping issue this morning too and had some success with those libraries. All of that For Loop stuff just can't touch the performance of numpy/pandas --- processing 4.5 million rows in a couple of minutes is no problem.
... View more
01-08-2015
09:21 AM
|
0
|
0
|
4537
|
|
POST
|
numpy and pandas are really good at selecting and grouping things. Something like this could work (needs to be tested though) import numpy
from pandas import *
#create numpy array from the table
nparr = arcpy.da.TableToNumPyArray(WIND, ["BLDG_ID", "HAZARD_ID"])
#turn it into a Pandas data frame
df = DataFrame(nparr, columns=["BLDG_ID", "HAZARD_ID"])
#new data frame with the selection criteria
df2 = df[df['HAZARD_ID'].isin([16,17,18])]
#do something meaningful with the filtered dataframe like convert it to a .csv file
df2.to_csv(r'C:\output.csv')
... View more
01-08-2015
08:56 AM
|
0
|
2
|
4537
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|