|
POST
|
Hi, If I get it right, you want to get values from Column 1 (Numeric) which corresponds to unique values from Column 3 (Text). Assuming there can be more then one unique numeric values for each text value from Column 3 i I would suggest using dictionary with Column 3 value as key and list of Column 1 values as value. One important thing is that each value in Column 1 can correspond only to one value in Column 3. Considering given assumptions code would be something like:
map_dict = {}
with arcpy.da.SearchCursor(fc, ['Colmun 3', 'Column 1'] as collector:
for row in collector:
if not row[0] in map_dict.keys():
map_dict[row[0]] = []
if not row[1] in map_dict[row[0]]:
map_dict[row[0]].append(row[1])
Now you can use
'Column1 in (%s)' % map_dict[Column3value].join(', ')
to build definition query, and Column3 value in other places. Hope it will help. Regards Arek
... View more
05-17-2013
01:11 AM
|
0
|
0
|
737
|
|
POST
|
Hi, Your script will work fine, as long as you wont use .txt file as input. The case is that tables in txt format are read-only. If you open this test.txt table in arcmap "Add Field" option in Table options will be inactive, why then you think it can be done by arcpy.AddField? I see two workarounds of this problem: 1). You can convert table to .dbf in script (arcpy.TableToTable_conversion) and then add and calculate field - if you don't need to keep data in txt format. 2). You can write function that open text file (open() function in python) and modifies it the way you want - it a bit harder task. Regards. Arek
... View more
05-10-2013
01:17 AM
|
0
|
0
|
817
|
|
POST
|
Hi, Corrected code with comments below: import arcpy # don't import modules if you're not gonna use them sys, string, os # Get the input from the model InputTable = arcpy.GetParameterAsText(0) InputArea = arcpy.GetParameterAsText(1) InputDepth = arcpy.GetParameterAsText(2) Newfield = "Volume" #Add Field arcpy.AddField_management(InputTable, Newfield, "DOUBLE", "", "","", "Vol","NON_NULLABLE","NON_REQUIRED","") #Calculate Field # field names should be wrapped in exclamation marks, function uses string #representation of expression, not real python expression Expression = '!%s! * !%s!' % (InputArea.upper(), InputDepth.upper()) # 'PYTHON' not 'Python' arcpy.CalculateField_management(InputTable, Newfield, Expression, "PYTHON") Generally speaking code should work, although I'm not sure if txt table can be changed that way, try with .dbf. Regards, Arek
... View more
05-09-2013
04:06 AM
|
0
|
0
|
817
|
|
POST
|
Hi, I think that it could be quite easy to implement it in Field Calculator, unless there are to many fields to check. Never heard about out-of-box solution. I would write python script as well. Regards Arek
... View more
04-30-2013
06:40 AM
|
0
|
0
|
4520
|
|
POST
|
Hi, Are you want to create filed that contains joined values from two other field? If so, what you're looking for is combination of arcpy.AddField_mangement and arcpy.CalculateField_management.
fields_to_join = ['!FIELD_NAME_1!', '!FIELD_NAME_2!'] # don't forget exclamation marks!
fc = 'C:/example.shp'
arcpy.AddField_management(fc, 'NEW_FIELD_NAME', 'TEXT')
arcpy.CalculateField_management(fc, 'NEW_FIELD_NAME', ''.join(fields_to_join), 'PYTHON')
If you want to use some separator between values from different fields change '' in: ''.join(fields_to_join) to 'separator' i.e.: '_'.join(fields_to_join) Hope it helps. Cheers Arek
... View more
04-30-2013
06:22 AM
|
0
|
0
|
636
|
|
POST
|
Hi, There are two bottlenecks in your code. You pointed out first which is calling arcpy.SelectLayerByAttribute_management multiple times, other is creating new arcpy.SearchCursor(fc) object for each matched FID. Your idea with dict is good. Below is code with more generic solution, which iterates through feature class and creates dictonary where key is FID and value is another dictionary that maps fieldname to its value for each row.
fields = [f.name for f in arcpy.ListFields(fc) if f.name.upper() not in ('FID', 'SHAPE')]
collector = arcpy.SearchCursor(fc)
data = {}
for feature in collector:
data[feature.FID] = {f: feature.getValue(f) for f in fields}
del collector
Getting LandCover field value from this would be: LandCover = data[i[0]]['LandCover'] You can simplify this to get only LandCover value - in this case I would suggest using arcpy.da.SearchCursor instead of arcpy.SearchCursor because of its efficiency. So it would be something like:
data = {}
with arcpy.da.SearchCursor(fc, ['FID', 'LandCover']) as collector:
for row in collector:
data[row[0]] = row[1]
Then getting value of LandCover field would be: LandCover = data[i[0]] Hope it help. Regards Arek
... View more
04-30-2013
05:29 AM
|
0
|
0
|
867
|
|
POST
|
Hi, I've already answered to your question in previous thread: http://forums.arcgis.com/threads/81296-can-t-export-correct-images-using-script-tool-works-fine-in-regular-script?p=287088#post287088 getParameterAsText() does exactly what it sounds, it's getting attribute as text (string if you prefer). So if you need any other type of parameter you need to convert it. tsi = arcpy.GetParameterAsText(1) units = arcpy.GetParameterAsText(2) interval = arcpy.time.EsriTimeDelta(tsi, units) In this code you pass two string variables to arcpy.time.EsriTimeDelta() changing line to : tsi = float(arcpy.GetParameterAsText(1)) Should resolve issue with interval type. Best Regards Arek
... View more
04-15-2013
04:32 AM
|
0
|
0
|
637
|
|
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
... View more
04-10-2013
07:58 AM
|
0
|
0
|
1678
|
|
POST
|
If you're using arcgis 10.1 I would suggest using arcpy.da.UpdateCursor instead of arcpy.UpdateCursor. It much faster and offers easy access to geometry (simply add 'SHAPE@' to field list), disadvantage is its less intuitive at the beginning. Regards, Arek
... View more
04-09-2013
02:51 AM
|
0
|
0
|
1409
|
|
POST
|
Hi, outCS = "NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet" Is not a string representation of CS. Use Spatial Reference object instead i.e. supposing you're using arcmap 10.1:
arcpy.SpatialReference("NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet")
or arcpy.SpatialReference(2927) Cheers. Arek
... View more
04-08-2013
05:20 AM
|
0
|
0
|
1227
|
|
POST
|
Hi, If you'll look at lines below (from your code) you will notice that you're overwriting row with itself, so i wouldn't expect any change in data: targetFCCur = arcpy.UpdateCursor(TargetFCPath) for targetFCRow in targetFCCur: ... nothing with targetFCRow done here ... targetFCCur.updateRow(targetFCRow) You should copy each field value from source row to target row, it won't happen by itself. Regards Arek
... View more
04-08-2013
12:07 AM
|
0
|
0
|
1409
|
|
POST
|
Hi, I'm using eclipse with installed pyDev, and can recommend this solution. Maybe it does'n have all features ipython has, but code completion works fine with arcpy, and it had a lot of customization options. Regards Arek
... View more
01-17-2013
04:09 AM
|
0
|
0
|
571
|
|
POST
|
Hi, How do you run your tool (as standalone script, toolbox, add-in)? You may try using tkinter module to display some input dialog to user at the beginning of run. Cheers Arek
... View more
01-14-2013
10:37 PM
|
0
|
0
|
311
|
|
POST
|
Use double backslashes ("\\") in paths (ie. on add_layer) instead of single ones, also mxds_path should be 'c:\\Temp2\\', not ('c:\Temp2') - no parenthesis, '\\' at end of string. That should do. Regards. Arek
... View more
01-13-2013
10:47 PM
|
0
|
0
|
1650
|
|
POST
|
Hi, Do you have to add to both mxds at the same time. Easiest way would be iteration over mxd files and addin lyr to one document at time (as below) Cheers Arek
import arcpy
add_layer = arcpy.mapping.Layer('C:\\Path\\to\\lyrfile.lyr')
mxds_path = 'c:\\path\\to\\mxds\\'
mxds = ['one.mxd', 'two.mxd']
for mxd_name in mxds:
mxd = arcpy.mapping.MapDocument(mxds_path + mxd_name)
df = arcpy.mapping.ListDataFrames(mxd, 'Layers1')[0]
arcpy.mapping.AddLayer(df, addLayer, "TOP")
mxd.save()
... View more
01-11-2013
05:19 AM
|
0
|
0
|
1650
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-05-2022 08:01 AM | |
| 1 | 03-29-2023 12:37 AM | |
| 2 | 08-06-2013 05:40 AM | |
| 1 | 11-15-2012 10:38 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-29-2023
03:19 PM
|