I have a line feature class (saved in a feature dataset within a File GDB) which is comprised of a set of intersecting lines.
I have used the Add Geometry tool to add Start_X
, Start_Y
, End_X
and End_Y
fields to the attribute table. The lines are not all orientated in the same direction, so for certain pairs of features in the table, End_X = End_X
and End_Y = End_Y
.
I want to use the Select Layer By Attributes tool with an SQL query (if possible) to select only lines in the table with matching end coordinates and then run the Flip Line tool on the selection in order to reverse the direction of the selected lines.
It's also worth noting that the OIDs are in a random order, e.g. line 1 may be connected to line 10.
Is it possible to use an SQL statement to select features in an attribute table based on the values of other features?
I tried
SELECT * FROM table_name WHERE:
END_X = END_X AND END_Y = END_Y AND OBJECTID <> OBJECTID
I'm sure it will be obvious to most that all that does is search each row individually and come up with nothing, though hopefully it gives an idea as to what I'm trying to do.
If it is not possible using SQL, is it something that could be done with Arcpy Search Cursors? (I am an extreme novice with Arcpy/Python scripting. I just know Search Cursors exist and can be used to find records in tables.)
Best Answer
I can think of a couple of options, if what you're saying is that the X and Y values both need to be the same, but the object ID different; one in ArcGIS, one in Microsoft Access.
ArcGIS:
Calculate a new string field (lets call it "END_XY_COMBO") that will be a combined value of your
END_X
andEND_Y
values for each row. Assuming your X/Y values are in number format, you'll need to convert to string, so calculate that new field like:END_XY_COMBO = str(!END_X!) + "-" + str(!END_Y!).
This will combine the two X/Y values separated by a dash.
Then export this table as a second copy of itself.
Then join the second copy to the first copy on the
"END_XY_COMBO"
field, then run a Select By Attributes, and select the records from table1where: TABLE1.ObjectID <> "TABLE2.ObjectID"
.This should select all records where the
END_X
andEND_Y
values are all the same, but the Object IDs are different.Microsoft Access:
"Match_Flag"
."END_X"
field, and create a second join between them on the"END_Y"
field (using one-to-one join, meaning values have to match in both fields in both tables)."Match_Flag"
field from Table 1 and set it toupdate to "Y"
.ObjectID
field from Table 1, leave the"Update To:"
part blank, but set the criteria to be:<> [Table2]![ObjectID].
- This will flag all records in table 1 where theEND_X
andEND_Y
values are the same, but theObjectID
values are different.ObjectID
, and select the records whereMatch_Flag = "Y"
.