|
POST
|
Bear with me, as today is the first time I've learned anything about Python and I'm a Model Builder n00b. Here's what I'm trying to do: Select one feature in the Place feature class Select all features in Tracts within a distance of negative 500 meters of the selected Place (I know this seems odd, but I have my reasons) Use the "Name" field value from the selected Place feature to calculate the values of the "City" field of the selected Tracts features Repeat for every feature in the Place feature class What I can't figure out is how to assign the "Name" value of the selected Place feature to the "City" field of the selected features in Tracts. The Field Calculator tool seems to only allow me to assign values from within the feature class. Here's what it looks like in Model Builder: (BTW, the "Value" output from "Iterate Feature Selection" just produces the number 25 for some reason. I can't seem to use that output as the input for the Calculate Field function.) [ATTACH=CONFIG]27121[/ATTACH] Thank you in advance for your help! -Rebecca Don't use an iterator at all. Do it with the Spatial Join tool. Make the Places the target feature and the Tracts the Join features and use the One To Many option and a negative 500 foot tolerance. This will do all of the overlays in one process and preserve the ObjectIDs and attributes of both the target (Places) and each Join Feature (Tract) in the output. You then can use the Make Feature Layer on the Tracts, and then use the Add Join tool on the Tract's ObjectID to the JoinFID field and use the Field Calculator tool to transfer the Place Name attribute to the Tract City field in a single calculation. No iterators needed. If for some reason the Negative 500 foot tolerance does not work directly with the Spatial Join tool, first run the Buffer tool with the negative buffer distance and then use the Spatial Join tool with the Buffer output as the Target Features or Join Features. If you were going to fix your present model you would have to create a variable such as %Name% to get the City name of the currently iterated Place feature and use that variable (%Name%) in the Field Calculator, since you have no common field to perform a Join without using the Spatial Join tool. You could do this with an iterate field values iterator or you needed to make Name part of the Group By field list of the Feature Selection iterator to have the Value variable populated by the City name. You probably left that blank, so the iterator is actually using the entire selection of 25 features to do one pass, which you definitely do not want.
... View more
08-30-2013
11:16 AM
|
0
|
0
|
4150
|
|
POST
|
I am trying to flip lines in a geometric network to match the flow direction and can't seem to find a tool to do this. I tried installing the Water Utility Network Editing for ArcGIS 10.2. I followed the directions to install and when I open the toolbar most of the tools show as "Missing". Are there any other ways to get this accomplished without the Water Utility Network Editing Add-In? Thanks! If you have at least a Standard (ArcEditor) license you can use the Flip Line tool under the Editor toolbox to flip all of the lines at once. This tool directly alters the original features without creating a copy, and it will not flip direction-dependent attributes, only line geometry. Therefore, you should first either create a copy of the entire feature class before flipping the lines or after you have selected the lines you intend to flip, export that set of features to a new feature class. Then you can use the Flip Line tool to alter the geometry followed by a Join to the copied features and using the Field Calculator to flip any direction-dependent attributes. If you have no unique ID field to export to do a standard join you could use the Spatial Join tool to get the matching Target ObjectID field values of your original lines needed to perform the join.
... View more
08-30-2013
10:18 AM
|
0
|
5
|
4420
|
|
POST
|
Jake, the script works with the feature class you provided, using the Python window within ArcMap. Yes, but it only worked because you selected one feature. If you select 2 features you will get nothing. That is why you have to use the IN operator to work with a list of 0 or more items. OBJECTID = 12345; 12346 is an invalid selection statement (not sure how Python resolves the list into the SQL statement, but = cannot be used with a list). OBJECTID IN (12345, 12346) is valid and will return both records. OBJECTID IN (12345; 12346) Returns nothing since a semicolon is invalid in an SQL list.
... View more
08-28-2013
10:49 AM
|
0
|
0
|
1892
|
|
POST
|
The result is the same whether I use dsc.fidSet, dsc.FidSet, or dsc.FIDSet. Are you positive your layer has a feature selection already applied? If nothing is selected, no FID values should be returned.
... View more
08-28-2013
10:38 AM
|
0
|
0
|
1892
|
|
POST
|
The feature class has over a million records. Printing that many records will take quite a while. The arcpy.AddMessage("Continue") value was returned. If there are a million FID values placed within the IN clause I don't know that there won't be an error. Try it on a much smaller set first. I suspect the cursor won't accept a string that big that it could pass to the query parser and performance would be horrible. If it is going to process the entire table don't include a where clause. If it is a selection based on some grouped attribute values include those fields in the field list and write a logical SQL expression that gets the selection. If you are doing it based on a spatial query and get a huge list, perhaps try feeding portions of the OID list in a for loop to the query expression if an error gets thrown or performance drops too drastically.
... View more
08-28-2013
08:48 AM
|
0
|
0
|
1969
|
|
POST
|
How many features do you have in your target feature class? If you print out the fidset, are all of these features included in the semicolon-delimited string? Can you post the results of printing the fidset from your dsc object? If the fidset is delimited with semicolons it will have to be changed so that the fid values are delimited by commas for the where clause SQL to work. The SQL IN operator only works with lists of values separated by commas. Nothing in SQL works with semicolon separated lists.
... View more
08-28-2013
07:56 AM
|
0
|
0
|
1969
|
|
POST
|
import arcpy
mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Lot_Lines", df)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.fidSet
if dsc.shapeType == "Polyline":
rows = arcpy.da.SearchCursor(tlyr, "OBJECTID = " + sel_set)
for row in rows:
arcLength = row.ARCLENGTH
shapeLength = row.Shape_Length
if arcLength > 0:
print arcLength
else:
print shapeLength
del row
del rows The error is in line 32, for row in rows: RuntimeError: An invalid SQL statement was used. I know the select Object ID works, because it changes values depending on the feature selected. When you switched back to the original cursor type you got no records because your where clause needs to use the IN operator not the = operator. The error using the new arcpy.da cursor is due to the cursor declaration syntax being different. With the arcpy data access (arcpy.da) cursor you have to supply a mandatory field name list prior to defining an optional where clause. Your code has no field list. At a minimum the field list would have to include OBJECTID, ARCLENGTH and Shape_Length. So this code: rows = arcpy.da.SearchCursor(tlyr, "OBJECTID = " + sel_set) should be changed to this code: rows = arcpy.da.SearchCursor(tlyr, ["OID@", "ARCLENGTH", "SHAPE@LENGTH"], "OBJECTID IN (" + sel_set +")") OID@ makes sure you get the correct ObjectID field name reference, regardless of the database. Possibly SHAPE@LENGTH should be Shape_Length, depending on whether you want to access a geodatabase length field or the actual shape geometry length. You also do not have to use field names again after getting the cursor. You can use numbers to represent the fields. So that means the code beyond that line could also change to: rows = arcpy.da.SearchCursor(tlyr, ["OID@", "ARCLENGTH", "SHAPE@LENGTH"], "OBJECTID IN (" + sel_set + ")")
for row in rows:
arcLength = row.[1]
shapeLength = row.[2]
if arcLength > 0:
print arcLength
else:
print shapeLength
del row
del row
... View more
08-28-2013
06:48 AM
|
0
|
0
|
1969
|
|
POST
|
I am using a Personal Geodatabase and i am not able to make out how i can return more than one value as of now, in the query. request help to modify my existing query in such a way that it suits where_clause of SelectLayerbyAttributes. As a beginner in arcobjects I honestly do not know what Summary statistics is. Regards, Pavan Summary Statistics is a geoprocessing tool, not ArcObjects per se, although it can be accessed through ArcObjects. Since it is a personal geodatabase, build the query in Access and look at the sql of the subqueries. If you can make it work there it should translate to the query. At least that is how I would approach it.
... View more
08-27-2013
06:08 AM
|
0
|
0
|
1803
|
|
POST
|
ok, I never use model builder but went ahead on your recommendation and here's how it looks after export! arcpy.CalculateField_management('bm_parcels_calc', "bm_parcels_calc.PARCEL_KEY", "!myDB.\"myNT\\myUsername\".%parcel.parcel_key!", "PYTHON_9.3", "") "!myDB.\"myNT\\myUsername\".%parcel.parcel_key!" seriously!!! I wouldn't have guessed! I would never have guessed either. Anyway, at least now you know it can work with a Join and the Field Calculator. Your code is almost certainly faster, especially since it appears to update 5 fields in one pass, where Field Calculator only can update 1 field in a pass and would have to be run 5 times to do the same.
... View more
08-26-2013
09:39 AM
|
0
|
0
|
3053
|
|
POST
|
Thanks for looking at this! arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "[parcelTv.parcel_key]", "VB", "") ## I get this: ## arcgisscripting.ExecuteError: ERROR 999999: Error executing function. ## Failed to execute (CalculateField). or for a Python calculation: arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "!parcelTv.parcel_key!", "PYTHON_9.3", "") ## I get this: ## arcgisscripting.ExecuteError: ERROR 000539: Invalid field parcelTv.parcel_key ## Failed to execute (CalculateField). ...so I'm glad you are having success, but your recommendation isn't working though I suspect it's a data type thing. The field I'm calculating is a Long, and the source is an OBJECTID, and it didn't like me trying to cast to long like this arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", long("!parcelTv.parcel_key!"), "PYTHON_9.3", "") ...and with that I think I'll stick with the cursor method for the speed. I'd love to testing the speed difference but as I can't get the high level tool method to work I suppose that's not going to happen. I'd guess 100 times faster though. 😉 You could get the tool to work if you built it in Model Builder and exported it to a Python Script. Also the problem is not a field data type error. Based on the error you posted, you have typed either an incorrect table name or an incorrect field name (most likely the table name) that does not actually exist in your join. You could definitely fix this error with the Query Builder interface available in the Model Builder Field Calculator tool to get the correct join field references and then export that to a Python script to get exactly the right values for your script, or get the correct join field names within ArcMap by manually doing the join and using the Query Builder in its Field Calculator. That is what I always do. I very rarely ever write any Field Calculator expressions directly in Idle. Also, there should be no need to cast the OBJECTID to a long. I never do. I just calc it straight in. Reading your code that worked for cursors your table appears to be named "parcel" and not "parcelTv". So these should work. arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "[parcel.parcel_key]", "VB", "") arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "!parcel.parcel_key!", "PYTHON_9.3", "") But if they don't work, the above methods for building the query expressions in Model Builder of ArcMap should be followed.
... View more
08-26-2013
08:16 AM
|
0
|
0
|
3053
|
|
POST
|
A similar post was left unanswered http://forums.arcgis.com/threads/29621-Selection-QUERY-duplicits?highlight=GROUP+BY , I had tried to do a workaround as mentioned in the link by using WHERE .. IN ( Select .. GROUP BY .. HAVING ..) but the problem I need to perform GROUP BY on multiple fields and need to Select Longitude and Latitude in Subquery, hence i cannot use "WHERE Longitude, Latitude IN" as you can use only one field while using IN. Request any kind of help. Regards, Pavan Unless you use a Personal Geodatabase (Access) or an SDE database like SQL Server or Oracle, GROUP BY can only return one value and cannot be correlated to any other fields in a table (I.e., the max is for every record in the entire table). A file geodatabase or shapefile do not support the subquery syntax you want to use. For those types of databases you must use the Summary Statistics tool and a join to do the selection based on the joined grouped summary values. A multi-field join would have to use the Make Query Table tool. Generally I breakdown and concatenate the multiple fields and use the Summary Statistics to do the selection or data transfer through a standard join.
... View more
08-26-2013
06:35 AM
|
0
|
0
|
1803
|
|
POST
|
I am rewriting the last set of calculations again. I found that I need to do too many replace updates with the table names as I do each direction and side (and even subarea for my large County). Even the field names need to be replaced sometimes if I do not do the process exactly the same each time. So I am making it easier to edit the input fields and increasing the readability of the calculations: From House Numbers Min_Meas = [CL_ENDS_LINES.MIN_MEAS]
Asc_Desc = [ADDRESS_ODD_RIGHT_Full.ASC_DESC]
Min_Min_Meas = [ADDRESS_ODD_RIGHT_Full.MIN_MIN_MEAS]
Max_Max_Meas = [ADDRESS_ODD_RIGHT_Full.MAX_MAX_MEAS]
House_Interval = [ADDRESS_ODD_RIGHT_Full.HOUSE_INTERVAL]
Min_From_House_Number = [ADDRESS_ODD_RIGHT_Full.MIN_FROM_HOUSE_NUMBER]
Max_To_House_Number = [ADDRESS_ODD_RIGHT_Full.MAX_TO_HOUSE_NUMBER]
Max_From_House_Number = [ADDRESS_ODD_RIGHT_Full.MAX_FROM_HOUSE_NUMBER]
Min_To_House_Number = [ADDRESS_ODD_RIGHT_Full.MIN_TO_HOUSE_NUMBER]
If Asc_Desc = "Ascending" AND Min_Meas < Min_Min_Meas Then
Raw = (Min_Meas - Min_Min_Meas) / House_Interval + Min_From_House_Number
Output = Round((Min_Meas - Min_Min_Meas) / House_Interval/2, 0) * 2 + Min_From_House_Number
If Output < Raw Then Output = Output + 2
ElseIf Asc_Desc = "Ascending" AND Min_Meas > Max_Max_Meas Then
Raw = (Min_Meas - Max_Max_Meas) / House_Interval + Max_To_House_Number
Output = Round((Min_Meas - Max_Max_Meas) / House_Interval/2, 0) * 2 + Max_To_House_Number
If Output < Raw Then Output = Output + 2
ElseIf Asc_Desc = "Descending" AND Min_Meas < Min_Min_Meas Then
Raw = (Min_Meas - Min_Min_Meas) / House_Interval + Max_From_House_Number
Output = Round((Min_Meas - Min_Min_Meas) / House_Interval/2, 0) * 2 + Max_From_House_Number
If Output > Raw Then Output = Output - 2
ElseIf Asc_Desc = "Descending" AND Min_Meas > Max_Max_Meas Then
Raw = (Min_Meas - Max_Max_Meas) / House_Interval + Min_To_House_Number
Output = Round((Min_Meas - Max_Max_Meas) / House_Interval/2, 0) * 2 + Min_To_House_Number
If Output > Raw Then Output = Output - 2
Else
Output = ""
End If To House Numbers Max_Meas = [CL_ENDS_LINES.MAX_MEAS]
Asc_Desc = [ADDRESS_ODD_RIGHT_Full.ASC_DESC]
Min_Min_Meas = [ADDRESS_ODD_RIGHT_Full.MIN_MIN_MEAS]
Max_Max_Meas = [ADDRESS_ODD_RIGHT_Full.MAX_MAX_MEAS]
House_Interval = [ADDRESS_ODD_RIGHT_Full.HOUSE_IINTERVAL]
Min_From_House_Number = [ADDRESS_ODD_RIGHT_Full.MIN_FROM_HOUSE_NUMBER]
Max_To_House_Number = [ADDRESS_ODD_RIGHT_Full.MAX_TO_HOUSE_NUMBER]
Max_From_House_Number = [ADDRESS_ODD_RIGHT_Full.MAX_FROM_HOUSE_NUMBER]
Min_To_House_Number = [ADDRESS_ODD_RIGHT_Full.MIN_TO_HOUSE_NUMBER]
If Asc_Desc = "Ascending" AND Max_Meas < Min_Min_Meas Then
Raw = (Max_Meas - Min_Min_Meas) / House_Interval + Min_From_House_Number
Output = Round((Max_Meas - Min_Min_Meas) / House_Interval/2, 0) * 2 + Min_From_House_Number
If Output > Raw Then Output = Output - 2
ElseIf Asc_Desc = "Ascending" AND Max_Meas > Max_Max_Meas Then
Raw = (Max_Meas - Max_Max_Meas) / House_Interval + Max_To_House_Number
Output = Round((Max_Meas - Max_Max_Meas) / House_Interval/2, 0) * 2 + Max_To_House_Number
If Output > Raw Then Output = Output - 2
ElseIf Asc_Desc = "Descending" AND Max_Meas < Min_Min_Meas Then
Raw = (Max_Meas - Min_Min_Meas) / House_Interval + Max_From_House_Number
Output = Round((Max_Meas - Min_Min_Meas) / House_Interval/2, 0) * 2 + Max_From_House_Number
If Output < Raw Then Output = Output + 2
ElseIf Asc_Desc = "Descending" AND Max_Meas > Max_Max_Meas Then
Raw = (Max_Meas - Max_Max_Meas) / House_Interval + Min_To_House_Number
Output = Round((Max_Meas - Max_Max_Meas) / House_Interval/2, 0) * 2 + Min_To_House_Number
If Output < Raw Then Output = Output + 2
Else
Output = ""
End If
... View more
08-24-2013
06:44 AM
|
0
|
0
|
1121
|
|
POST
|
While you are welcome to solve your problem without using a join and the field calculator, you are flat out wrong that Python does not calculate across inner joins. I do it in practically every model I build and it works if I converted the Join and calculation from Model Builder to Python script. You needed to build it using Model Builder with the query parser and then export it to Python before declaring that it cannot be done. Here is an example that works every week for me: # Process: Calculate First_STNAME Field... arcpy.CalculateField_management(RDNUMBER_Routes_Layer, "RDNUMBER_Routes.First_STNAME", "[RDNUMBERS_ALL.FIRST_STNAME]", "VB", "") So based on this example (which I had not looked up previously and could not test before) I can now point out what you needed to do to make your original code work. You had: arcpy.CalculateField_management('calcLyr',"PARCEL_KEY", 'parcelTv.parcel_key') which had several errors. You had not included the feature class qualifier for the field to be calculated, you had not enclosed the calculation expression with field delimiters and you had not specified the Parser. So correcting your code to work, here is how the syntax should have been for a VB calculation (faster than Python with joins at 10.0): arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "[parcelTv.parcel_key]", "VB", "") or for a Python calculation: arcpy.CalculateField_management('calcLyr', "bm_parcels_calc.PARCEL_KEY", "!parcelTv.parcel_key!", "PYTHON_9.3", "") I also agree that the code you came up with is faster, especially as more fields are compared or transferred. I have used that code technique recently to fill in Null values for 34 fields in a table prior to making those fields not accept Null values in a new feature class and it is definitely faster. I just don't want misinformation about what can or cannot be done with Python using joins and the field calculator to go uncorrected.
... View more
08-23-2013
02:35 PM
|
0
|
0
|
3053
|
|
POST
|
I am assuming your data is based on just a Geographic Coordinate System and only uses decimal degrees for its coordinate values. If so, I believe you can only use angular units to work with that data. You would need to use the Project tool to convert it to a Projected Coordinate System that uses linear units such as meters and that is designed to project area correctly. Once you have chosen a good projection use the Project tool to transform your data into a new feature class you can buffer with linear units such as meters. Melita Kennedy is the resident ESRI projection expert on the forum. Here is some advice she has given others on the subject of choosing an equal areas projection: "You'll want to use an equal-area projection. You'll find some for the US under projected coordinate systems, continental, north america like "USA Contiguous Albers Equal Area Conic USGS". You could modify it and change the central meridian and standard parallels into your area of interest, but I'm not sure the census data is accurate enough to warrant that. When we've done testing of various equal area projections, the density of the data (how many vertices) had a greater effect that which equal area projection was used."
... View more
08-23-2013
02:10 PM
|
0
|
0
|
1051
|
|
POST
|
Why doesn't this work?! I'm going nuts! addrTbl = r'Database Connections\Connection to blah.sde\blah.dbo.addr' parcelTbl = r'Database Connections\Connection to blah.sde\blah.dbo.parcel' arcpy.MakeTableView_management(parcelTbl, 'parcelTv') arcpy.MakeFeatureLayer_management('default.gdb\\bm_parcels_calc', 'calcLyr') arcpy.AddJoin_management('calcLyr', "PARCEL_PIN", 'parcelTv',"parcel_id","KEEP_ALL") # works to here. arcpy.CalculateField_management('calcLyr',"PARCEL_KEY", 'parcelTv.parcel_key') Show me how to fix it and I'll buy you lunch at next years UC! I believe you forgot to qualify the calclyr PARCEL_KEY field with the underlying feature class name, especially since both the fc and table have the PARCEL_KEY field. So I believe it should be (double check the single/double quotes also): arcpy.CalculateField_management('calcLyr','bm_parcels_calc.PARCEL_KEY', 'parcelTv.parcel_key')
... View more
08-23-2013
10:30 AM
|
0
|
0
|
3053
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-24-2026 11:37 PM | |
| 1 | 03-24-2026 08:01 PM | |
| 7 | 02-23-2026 08:34 AM | |
| 1 | 03-31-2025 03:25 PM | |
| 1 | 03-28-2025 06:54 PM |
| Online Status |
Offline
|
| Date Last Visited |
07-09-2026
12:59 AM
|