Flip subset of lines using arcpy.FlipLine_edit in a Python script

2177
2
Jump to solution
03-12-2014 09:45 AM
DarrenMcCormick
New Contributor
In a Python script I can't seem to get FlipLine_edit to work on a selected set of lines contained within a shapefile. Unfortunately, all of the lines are getting flipped instead of just those that are selected.

Steps I am using (note code snippet pasted below, full script attached):


  1. Create a layer using MakeFeatureLayer

  2. Count all lines using GetCount (report result with print statement)

  3. Select a subset of lines using SelectLayerByAttribute

  4. Count selected lines using GetCount (report result with print statement)

  5. Attempt to change direction of selected lines using FlipLine_edit

arcpy.MakeFeatureLayer_management(shpLine, "lyrLines") strCountAll = str(arcpy.GetCount_management("lyrLines")) print "Count of all features is " + strCountAll arcpy.SelectLayerByAttribute_management("lyrLines", "NEW_SELECTION", '"Flip_yn" = \'yes\'') strCountSelected = str(arcpy.GetCount_management("lyrLines")) print "Count of selected features is " + strCountSelected arcpy.FlipLine_edit(shpLine) arcpy.SelectLayerByAttribute_management("lyrLines", "CLEAR_SELECTION") 


In ArcMap, when using the Flip Line tool contained within Editing Tools:

  • No lines selected: all lines will be flipped

  • One line selected: the selected line will be flipped

FYI: I have 64-bit Windows 7 with ArcGIS 10.1 (ArcInfo license) and both Python 2.7.2 and Pythonwin (both 2.7.2)

I also tried using FlipLine using arcpy.da.UpdateCursor, but individual lines were not being flipped this way either.

Thanks in advance for any input!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
In a Python script I can't seem to get FlipLine_edit to work on a selected set of lines contained within a shapefile. Unfortunately, all of the lines are getting flipped instead of just those that are selected.

Steps I am using (note code snippet pasted below, full script attached):


  1. Create a layer using MakeFeatureLayer

  2. Count all lines using GetCount (report result with print statement)

  3. Select a subset of lines using SelectLayerByAttribute

  4. Count selected lines using GetCount (report result with print statement)

  5. Attempt to change direction of selected lines using FlipLine_edit

arcpy.MakeFeatureLayer_management(shpLine, "lyrLines") strCountAll = str(arcpy.GetCount_management("lyrLines")) print "Count of all features is " + strCountAll arcpy.SelectLayerByAttribute_management("lyrLines", "NEW_SELECTION", '"Flip_yn" = \'yes\'') strCountSelected = str(arcpy.GetCount_management("lyrLines")) print "Count of selected features is " + strCountSelected arcpy.FlipLine_edit(shpLine) arcpy.SelectLayerByAttribute_management("lyrLines", "CLEAR_SELECTION") 


In ArcMap, when using the Flip Line tool contained within Editing Tools:

  • No lines selected: all lines will be flipped

  • One line selected: the selected line will be flipped

FYI: I have 64-bit Windows 7 with ArcGIS 10.1 (ArcInfo license) and both Python 2.7.2 and Pythonwin (both 2.7.2)

I also tried using FlipLine using arcpy.da.UpdateCursor, but individual lines were not being flipped this way either.

Thanks in advance for any input!


Your code is flipping every line because you are feeding the FlipLine_edit tool the shapefile (shpLine) directly, not the layer with the selection ("lyrLines").  It is flipping the shapefile on disk itself like it is being done from ArcCatalog, not from a Desktop layer.  Try feeding it the "lyrLines" layer instead.  Only layers contain selections, not shapefile objects themselves.

View solution in original post

0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor
In a Python script I can't seem to get FlipLine_edit to work on a selected set of lines contained within a shapefile. Unfortunately, all of the lines are getting flipped instead of just those that are selected.

Steps I am using (note code snippet pasted below, full script attached):


  1. Create a layer using MakeFeatureLayer

  2. Count all lines using GetCount (report result with print statement)

  3. Select a subset of lines using SelectLayerByAttribute

  4. Count selected lines using GetCount (report result with print statement)

  5. Attempt to change direction of selected lines using FlipLine_edit

arcpy.MakeFeatureLayer_management(shpLine, "lyrLines") strCountAll = str(arcpy.GetCount_management("lyrLines")) print "Count of all features is " + strCountAll arcpy.SelectLayerByAttribute_management("lyrLines", "NEW_SELECTION", '"Flip_yn" = \'yes\'') strCountSelected = str(arcpy.GetCount_management("lyrLines")) print "Count of selected features is " + strCountSelected arcpy.FlipLine_edit(shpLine) arcpy.SelectLayerByAttribute_management("lyrLines", "CLEAR_SELECTION") 


In ArcMap, when using the Flip Line tool contained within Editing Tools:

  • No lines selected: all lines will be flipped

  • One line selected: the selected line will be flipped

FYI: I have 64-bit Windows 7 with ArcGIS 10.1 (ArcInfo license) and both Python 2.7.2 and Pythonwin (both 2.7.2)

I also tried using FlipLine using arcpy.da.UpdateCursor, but individual lines were not being flipped this way either.

Thanks in advance for any input!


Your code is flipping every line because you are feeding the FlipLine_edit tool the shapefile (shpLine) directly, not the layer with the selection ("lyrLines").  It is flipping the shapefile on disk itself like it is being done from ArcCatalog, not from a Desktop layer.  Try feeding it the "lyrLines" layer instead.  Only layers contain selections, not shapefile objects themselves.
0 Kudos
DarrenMcCormick
New Contributor
Hi Richard:

The info in your reply post solved the problem. I should have known this - doh!

Thanks so much!

-Darren
0 Kudos