Automating line adjustment to a point or a series of points in ArcGIS Suite?ERROR 000800 when trying to snap points layer to line or buffer layer?Snapping “Point to Line” Results to Correct Streets in ArcGIS for Desktop?Showing directional line symbol in ArcGIS for Desktop?Transposing data points to line using ArcGIS DesktopSplit 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?

Fill your bucket with 2020

Identifying Wires behind Light Switch

Putting tools you use (but can't configure) on resume?

What is the relative return point (i.e. the "space it left") of a creature banished by the Banishment spell?

Why there is difference between performance of Vanguard S&P500 (VUSA) and S&P500 index

Are there any sets where it is an open question whether the set is open (or closed)?

Can every manifold be turned into a Lie group?

Reuse a part of a tikz picture with savebox

Do any printing presses exist in the Forgotten Realms?

Can I rescind my offer of working on weekends after last day?

A short story (possibility written in the 80's), where humans visit an alien race that evolves fast?

How bad is 1. e4 c5 2. Nf3 d6 3. a3?

When does one use an extra stave for piano music?

Moving into check for a draw as black, why is it illegal? Comparison to Racing Kings

Why is Leela so good at beating Stockfish in the French/Caro-Kann?

How to Quickly Replace a Parameter in a Piped Command Chain

Help identifying 8 pin connector

How and why is my site being abused?

Is it possible to conserve the total kinetic energy of a system, but not its momentum?

Why is the OS obfuscation defense against "It's a Unix system!" not widely implemented?

What would have been the typical drinks for a US farmer in the late 18th/early 19th century?

Creating 2020 in the fewest number of steps

Does Special Relativity Imply Multiple Realities?

How would I measure the Carbon Dioxide content in Coca Cola over a period of time?



Automating line adjustment to a point or a series of points in ArcGIS Suite?


ERROR 000800 when trying to snap points layer to line or buffer layer?Snapping “Point to Line” Results to Correct Streets in ArcGIS for Desktop?Showing directional line symbol in ArcGIS for Desktop?Transposing data points to line using ArcGIS DesktopSplit 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?






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









5


















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
    Oct 2 at 19:34











  • 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
    Oct 2 at 19:40











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

    – FelixIP
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:52

















5


















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
    Oct 2 at 19:34











  • 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
    Oct 2 at 19:40











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

    – FelixIP
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:52













5













5









5








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








edited Oct 3 at 23:15







JMNC

















asked Oct 2 at 19:31









JMNCJMNC

1738 bronze badges




1738 bronze badges















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

    – Mapperz
    Oct 2 at 19:34











  • 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
    Oct 2 at 19:40











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

    – FelixIP
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:52

















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

    – Mapperz
    Oct 2 at 19:34











  • 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
    Oct 2 at 19:40











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

    – FelixIP
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:45











  • 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
    Oct 2 at 19:52
















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

– Mapperz
Oct 2 at 19:34





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

– Mapperz
Oct 2 at 19:34













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
Oct 2 at 19:40





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
Oct 2 at 19:40













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

– FelixIP
Oct 2 at 19:45





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

– FelixIP
Oct 2 at 19:45













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
Oct 2 at 19:45





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
Oct 2 at 19:45













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
Oct 2 at 19:52





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
Oct 2 at 19:52










2 Answers
2






active

oldest

votes


















2



















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
    Oct 2 at 22:59







  • 1





    Add join field will immediately bring attributes into new line.

    – FelixIP
    Oct 2 at 23:12


















4



















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




















  • 1





    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

    – Hornbydd
    Oct 3 at 23:01






  • 1





    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

    – Ben Gosack
    Oct 4 at 14:49












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%2fautomating-line-adjustment-to-a-point-or-a-series-of-points-in-arcgis-suite%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









2



















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
    Oct 2 at 22:59







  • 1





    Add join field will immediately bring attributes into new line.

    – FelixIP
    Oct 2 at 23:12















2



















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
    Oct 2 at 22:59







  • 1





    Add join field will immediately bring attributes into new line.

    – FelixIP
    Oct 2 at 23:12













2















2











2









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








edited Oct 2 at 22:07

























answered Oct 2 at 21:51









FelixIPFelixIP

17.8k1 gold badge18 silver badges47 bronze badges




17.8k1 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
    Oct 2 at 22:59







  • 1





    Add join field will immediately bring attributes into new line.

    – FelixIP
    Oct 2 at 23:12

















  • 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
    Oct 2 at 22:59







  • 1





    Add join field will immediately bring attributes into new line.

    – FelixIP
    Oct 2 at 23:12
















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
Oct 2 at 22:59






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
Oct 2 at 22:59





1




1





Add join field will immediately bring attributes into new line.

– FelixIP
Oct 2 at 23:12





Add join field will immediately bring attributes into new line.

– FelixIP
Oct 2 at 23:12













4



















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




















  • 1





    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

    – Hornbydd
    Oct 3 at 23:01






  • 1





    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

    – Ben Gosack
    Oct 4 at 14:49















4



















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




















  • 1





    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

    – Hornbydd
    Oct 3 at 23:01






  • 1





    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

    – Ben Gosack
    Oct 4 at 14:49













4















4











4









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










answered Oct 2 at 22:24









Ben GosackBen Gosack

1,0385 silver badges11 bronze badges




1,0385 silver badges11 bronze badges










  • 1





    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

    – Hornbydd
    Oct 3 at 23:01






  • 1





    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

    – Ben Gosack
    Oct 4 at 14:49












  • 1





    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

    – Hornbydd
    Oct 3 at 23:01






  • 1





    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

    – Ben Gosack
    Oct 4 at 14:49







1




1





This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

– Hornbydd
Oct 3 at 23:01





This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.

– Hornbydd
Oct 3 at 23:01




1




1





@Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

– Ben Gosack
Oct 4 at 14:49





@Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.

– Ben Gosack
Oct 4 at 14:49


















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%2fautomating-line-adjustment-to-a-point-or-a-series-of-points-in-arcgis-suite%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

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?