How do I automate adjusting a line to a point or a series of points in ArcGIS Suite?Snapping “Point to Line” Results to Correct Streets in ArcGIS for Desktop?How to transpose data points to a line efficiently?Split Line at Points not splitting at every point in ArcGIS for Desktop?Snapping end lines ArcGIS 10.4Letting multiple lines coincide into one line using ArcGIS Desktop?“Locate features along routes” tool and line features - how to use XY tolerance?

Slow coworker receiving compliments while I receive complaints

Consecutive numbers that are Manhattan distance 3 apart

Test if two food are the same

How to execute a project with two resources where you need three resources?

An employee has low self-confidence, and is performing poorly. How can I help?

Why didn't Kes send Voyager home?

Any historical references to links between JOSS and BASIC?

how do you value what your leisure time is worth?

Is there a reason behind the 'Ending' joke?

Why is the logical NOT operator in C-style languages "!" and not "~~"?

Suspicious crontab entry

What term would be used for words that are borrowed from Japanese and used in other languages?

What is this plane with its thick cockpit?

How to remind myself to lock my doors

What powers an aircraft prior to the APU being switched on?

Does the Creighton Method of Natural Family Planning have a failure rate of 3.2% or less?

Conveying the idea of " judge a book by its cover" by " juger un livre par sa couverture"

Adding elements to some sublists of unequal length

Little Endian Number to String Conversion

How do I automate adjusting a line to a point or a series of points in ArcGIS Suite?

Are there any privately owned large commercial airports?

Does Australia produce unique 'specialty steel'?

A Society Built Around Theft?

What is this plant with small red fruits?



How do I automate adjusting a line to a point or a series of points in ArcGIS Suite?


Snapping “Point to Line” Results to Correct Streets in ArcGIS for Desktop?How to transpose data points to a line efficiently?Split Line at Points not splitting at every point in ArcGIS for Desktop?Snapping end lines ArcGIS 10.4Letting multiple lines coincide into one line using ArcGIS Desktop?“Locate features along routes” tool and line features - how to use XY tolerance?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









3

















There are multiple toolboxes in ArcGIS Suite that deal with geographic transformation and correction, such as Spatial Adjustment, Rubbersheeting, and Snap. I'm not sure how to best use a tool to correct my line to a series of points as shown in image #3:



Snapping a line to points



1) is what I currently have;

2) is what I get when I use the Snap tool; and

3) is what I want.



The points are considered accurate geographic "anchors" for the lines, but don't otherwise share any field attributes with the lines. I have access to a list of all of the point coordinates.



If I snap the line without vertices with the Snap tool, the tool doesn't work at all, even with a high tolerance set (higher than the distance between the line and the point).



I'd like to stick to ArcGIS Suite, and to use something that has a corresponding arcpy tool. I realize that I can move the anchors/delete the middle anchor (vertex) to get the shape in Figure #3, but I plan on automating this process because I have hundreds of lines and thousands of points.










share|improve this question




























  • 1: Generalize your line 2: snap your generalized line to your anchors

    – Mapperz
    8 hours ago











  • Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

    – JMNC
    8 hours ago











  • Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

    – FelixIP
    8 hours ago











  • you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

    – Mapperz
    7 hours ago











  • I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

    – JMNC
    7 hours ago

















3

















There are multiple toolboxes in ArcGIS Suite that deal with geographic transformation and correction, such as Spatial Adjustment, Rubbersheeting, and Snap. I'm not sure how to best use a tool to correct my line to a series of points as shown in image #3:



Snapping a line to points



1) is what I currently have;

2) is what I get when I use the Snap tool; and

3) is what I want.



The points are considered accurate geographic "anchors" for the lines, but don't otherwise share any field attributes with the lines. I have access to a list of all of the point coordinates.



If I snap the line without vertices with the Snap tool, the tool doesn't work at all, even with a high tolerance set (higher than the distance between the line and the point).



I'd like to stick to ArcGIS Suite, and to use something that has a corresponding arcpy tool. I realize that I can move the anchors/delete the middle anchor (vertex) to get the shape in Figure #3, but I plan on automating this process because I have hundreds of lines and thousands of points.










share|improve this question




























  • 1: Generalize your line 2: snap your generalized line to your anchors

    – Mapperz
    8 hours ago











  • Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

    – JMNC
    8 hours ago











  • Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

    – FelixIP
    8 hours ago











  • you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

    – Mapperz
    7 hours ago











  • I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

    – JMNC
    7 hours ago













3












3








3








There are multiple toolboxes in ArcGIS Suite that deal with geographic transformation and correction, such as Spatial Adjustment, Rubbersheeting, and Snap. I'm not sure how to best use a tool to correct my line to a series of points as shown in image #3:



Snapping a line to points



1) is what I currently have;

2) is what I get when I use the Snap tool; and

3) is what I want.



The points are considered accurate geographic "anchors" for the lines, but don't otherwise share any field attributes with the lines. I have access to a list of all of the point coordinates.



If I snap the line without vertices with the Snap tool, the tool doesn't work at all, even with a high tolerance set (higher than the distance between the line and the point).



I'd like to stick to ArcGIS Suite, and to use something that has a corresponding arcpy tool. I realize that I can move the anchors/delete the middle anchor (vertex) to get the shape in Figure #3, but I plan on automating this process because I have hundreds of lines and thousands of points.










share|improve this question
















There are multiple toolboxes in ArcGIS Suite that deal with geographic transformation and correction, such as Spatial Adjustment, Rubbersheeting, and Snap. I'm not sure how to best use a tool to correct my line to a series of points as shown in image #3:



Snapping a line to points



1) is what I currently have;

2) is what I get when I use the Snap tool; and

3) is what I want.



The points are considered accurate geographic "anchors" for the lines, but don't otherwise share any field attributes with the lines. I have access to a list of all of the point coordinates.



If I snap the line without vertices with the Snap tool, the tool doesn't work at all, even with a high tolerance set (higher than the distance between the line and the point).



I'd like to stick to ArcGIS Suite, and to use something that has a corresponding arcpy tool. I realize that I can move the anchors/delete the middle anchor (vertex) to get the shape in Figure #3, but I plan on automating this process because I have hundreds of lines and thousands of points.







arcgis-desktop arcpy arcgis-pro digitizing conflation






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








edited 7 hours ago









PolyGeo

55.4k17 gold badges88 silver badges262 bronze badges




55.4k17 gold badges88 silver badges262 bronze badges










asked 8 hours ago









JMNCJMNC

638 bronze badges




638 bronze badges















  • 1: Generalize your line 2: snap your generalized line to your anchors

    – Mapperz
    8 hours ago











  • Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

    – JMNC
    8 hours ago











  • Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

    – FelixIP
    8 hours ago











  • you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

    – Mapperz
    7 hours ago











  • I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

    – JMNC
    7 hours ago

















  • 1: Generalize your line 2: snap your generalized line to your anchors

    – Mapperz
    8 hours ago











  • Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

    – JMNC
    8 hours ago











  • Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

    – FelixIP
    8 hours ago











  • you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

    – Mapperz
    7 hours ago











  • I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

    – JMNC
    7 hours ago
















1: Generalize your line 2: snap your generalized line to your anchors

– Mapperz
8 hours ago





1: Generalize your line 2: snap your generalized line to your anchors

– Mapperz
8 hours ago













Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

– JMNC
8 hours ago





Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.

– JMNC
8 hours ago













Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

– FelixIP
8 hours ago





Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.

– FelixIP
8 hours ago













you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

– Mapperz
7 hours ago





you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…

– Mapperz
7 hours ago













I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

– JMNC
7 hours ago





I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.

– JMNC
7 hours ago










2 Answers
2






active

oldest

votes


















1


















Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:



enter image description here



Rename original lines in table of content to "original" and use field calculator:



g = arcpy.Geometry()
geometryList=arcpy.CopyFeatures_management("original",g)
def getChainage(lineFID,point):
line=geometryList[lineFID]
return line.measureOnLine(point.firstPoint)
#------------
getChainage( !NEAR_FID!, !Shape! )


To populate new field in points table:



enter image description here



Points to line tool will do the rest:



arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")


enter image description here



Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.






share|improve this answer




























  • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

    – JMNC
    4 hours ago












  • Add join field will immediately bring attributes into new line.

    – FelixIP
    4 hours ago


















2


















I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.



# assumes one line in in_line
in_line = r'scratch.gdbsample_line'
in_points = r'scratch.gdbsample_points'

# get line start and end points
with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur:
for row in cur:
geom = row[0]
point_first = geom.firstPoint
coord_first = [point_first.X, point_first.Y]
point_last = geom.lastPoint
coord_last = [point_last.X, point_last.Y]

# get point coords as list
with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur:
points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

# define a function used to sort points based on proximity to point_first
def coord_dif(coord_x):
x_dif = abs(coord_first[0] - coord_x[0])
y_dif = abs(coord_first[1] - coord_x[1])
return (x_dif + y_dif)

# sort points
points = sorted(points, key=coord_dif)
all_points = [coord_first] + points + [coord_last]

# construct geometry
line_geom = arcpy.Polyline(
arcpy.Array(
[arcpy.Point(pt[0], pt[1]) for pt in all_points]
)
)

# update with new line goemetry
with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur:
for row in cur:
cur.updateRow([line_geom])


before



after






share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f337590%2fhow-do-i-automate-adjusting-a-line-to-a-point-or-a-series-of-points-in-arcgis-su%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1


















    Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:



    enter image description here



    Rename original lines in table of content to "original" and use field calculator:



    g = arcpy.Geometry()
    geometryList=arcpy.CopyFeatures_management("original",g)
    def getChainage(lineFID,point):
    line=geometryList[lineFID]
    return line.measureOnLine(point.firstPoint)
    #------------
    getChainage( !NEAR_FID!, !Shape! )


    To populate new field in points table:



    enter image description here



    Points to line tool will do the rest:



    arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")


    enter image description here



    Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.






    share|improve this answer




























    • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

      – JMNC
      4 hours ago












    • Add join field will immediately bring attributes into new line.

      – FelixIP
      4 hours ago















    1


















    Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:



    enter image description here



    Rename original lines in table of content to "original" and use field calculator:



    g = arcpy.Geometry()
    geometryList=arcpy.CopyFeatures_management("original",g)
    def getChainage(lineFID,point):
    line=geometryList[lineFID]
    return line.measureOnLine(point.firstPoint)
    #------------
    getChainage( !NEAR_FID!, !Shape! )


    To populate new field in points table:



    enter image description here



    Points to line tool will do the rest:



    arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")


    enter image description here



    Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.






    share|improve this answer




























    • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

      – JMNC
      4 hours ago












    • Add join field will immediately bring attributes into new line.

      – FelixIP
      4 hours ago













    1














    1










    1









    Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:



    enter image description here



    Rename original lines in table of content to "original" and use field calculator:



    g = arcpy.Geometry()
    geometryList=arcpy.CopyFeatures_management("original",g)
    def getChainage(lineFID,point):
    line=geometryList[lineFID]
    return line.measureOnLine(point.firstPoint)
    #------------
    getChainage( !NEAR_FID!, !Shape! )


    To populate new field in points table:



    enter image description here



    Points to line tool will do the rest:



    arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")


    enter image description here



    Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.






    share|improve this answer
















    Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:



    enter image description here



    Rename original lines in table of content to "original" and use field calculator:



    g = arcpy.Geometry()
    geometryList=arcpy.CopyFeatures_management("original",g)
    def getChainage(lineFID,point):
    line=geometryList[lineFID]
    return line.measureOnLine(point.firstPoint)
    #------------
    getChainage( !NEAR_FID!, !Shape! )


    To populate new field in points table:



    enter image description here



    Points to line tool will do the rest:



    arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")


    enter image description here



    Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.







    share|improve this answer















    share|improve this answer




    share|improve this answer



    share|improve this answer








    edited 5 hours ago

























    answered 5 hours ago









    FelixIPFelixIP

    17.2k1 gold badge18 silver badges47 bronze badges




    17.2k1 gold badge18 silver badges47 bronze badges















    • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

      – JMNC
      4 hours ago












    • Add join field will immediately bring attributes into new line.

      – FelixIP
      4 hours ago

















    • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

      – JMNC
      4 hours ago












    • Add join field will immediately bring attributes into new line.

      – FelixIP
      4 hours ago
















    I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

    – JMNC
    4 hours ago






    I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.

    – JMNC
    4 hours ago














    Add join field will immediately bring attributes into new line.

    – FelixIP
    4 hours ago





    Add join field will immediately bring attributes into new line.

    – FelixIP
    4 hours ago













    2


















    I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.



    # assumes one line in in_line
    in_line = r'scratch.gdbsample_line'
    in_points = r'scratch.gdbsample_points'

    # get line start and end points
    with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur:
    for row in cur:
    geom = row[0]
    point_first = geom.firstPoint
    coord_first = [point_first.X, point_first.Y]
    point_last = geom.lastPoint
    coord_last = [point_last.X, point_last.Y]

    # get point coords as list
    with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur:
    points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

    # define a function used to sort points based on proximity to point_first
    def coord_dif(coord_x):
    x_dif = abs(coord_first[0] - coord_x[0])
    y_dif = abs(coord_first[1] - coord_x[1])
    return (x_dif + y_dif)

    # sort points
    points = sorted(points, key=coord_dif)
    all_points = [coord_first] + points + [coord_last]

    # construct geometry
    line_geom = arcpy.Polyline(
    arcpy.Array(
    [arcpy.Point(pt[0], pt[1]) for pt in all_points]
    )
    )

    # update with new line goemetry
    with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur:
    for row in cur:
    cur.updateRow([line_geom])


    before



    after






    share|improve this answer






























      2


















      I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.



      # assumes one line in in_line
      in_line = r'scratch.gdbsample_line'
      in_points = r'scratch.gdbsample_points'

      # get line start and end points
      with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur:
      for row in cur:
      geom = row[0]
      point_first = geom.firstPoint
      coord_first = [point_first.X, point_first.Y]
      point_last = geom.lastPoint
      coord_last = [point_last.X, point_last.Y]

      # get point coords as list
      with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur:
      points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

      # define a function used to sort points based on proximity to point_first
      def coord_dif(coord_x):
      x_dif = abs(coord_first[0] - coord_x[0])
      y_dif = abs(coord_first[1] - coord_x[1])
      return (x_dif + y_dif)

      # sort points
      points = sorted(points, key=coord_dif)
      all_points = [coord_first] + points + [coord_last]

      # construct geometry
      line_geom = arcpy.Polyline(
      arcpy.Array(
      [arcpy.Point(pt[0], pt[1]) for pt in all_points]
      )
      )

      # update with new line goemetry
      with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur:
      for row in cur:
      cur.updateRow([line_geom])


      before



      after






      share|improve this answer




























        2














        2










        2









        I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.



        # assumes one line in in_line
        in_line = r'scratch.gdbsample_line'
        in_points = r'scratch.gdbsample_points'

        # get line start and end points
        with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur:
        for row in cur:
        geom = row[0]
        point_first = geom.firstPoint
        coord_first = [point_first.X, point_first.Y]
        point_last = geom.lastPoint
        coord_last = [point_last.X, point_last.Y]

        # get point coords as list
        with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur:
        points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

        # define a function used to sort points based on proximity to point_first
        def coord_dif(coord_x):
        x_dif = abs(coord_first[0] - coord_x[0])
        y_dif = abs(coord_first[1] - coord_x[1])
        return (x_dif + y_dif)

        # sort points
        points = sorted(points, key=coord_dif)
        all_points = [coord_first] + points + [coord_last]

        # construct geometry
        line_geom = arcpy.Polyline(
        arcpy.Array(
        [arcpy.Point(pt[0], pt[1]) for pt in all_points]
        )
        )

        # update with new line goemetry
        with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur:
        for row in cur:
        cur.updateRow([line_geom])


        before



        after






        share|improve this answer














        I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.



        # assumes one line in in_line
        in_line = r'scratch.gdbsample_line'
        in_points = r'scratch.gdbsample_points'

        # get line start and end points
        with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur:
        for row in cur:
        geom = row[0]
        point_first = geom.firstPoint
        coord_first = [point_first.X, point_first.Y]
        point_last = geom.lastPoint
        coord_last = [point_last.X, point_last.Y]

        # get point coords as list
        with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur:
        points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

        # define a function used to sort points based on proximity to point_first
        def coord_dif(coord_x):
        x_dif = abs(coord_first[0] - coord_x[0])
        y_dif = abs(coord_first[1] - coord_x[1])
        return (x_dif + y_dif)

        # sort points
        points = sorted(points, key=coord_dif)
        all_points = [coord_first] + points + [coord_last]

        # construct geometry
        line_geom = arcpy.Polyline(
        arcpy.Array(
        [arcpy.Point(pt[0], pt[1]) for pt in all_points]
        )
        )

        # update with new line goemetry
        with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur:
        for row in cur:
        cur.updateRow([line_geom])


        before



        after







        share|improve this answer













        share|improve this answer




        share|improve this answer



        share|improve this answer










        answered 5 hours ago









        Ben GosackBen Gosack

        9434 silver badges10 bronze badges




        9434 silver badges10 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f337590%2fhow-do-i-automate-adjusting-a-line-to-a-point-or-a-series-of-points-in-arcgis-su%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單