<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Aligning random Address Points to a straight line. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/aligning-random-address-points-to-a-straight-line/m-p/1309700#M71227</link>
    <description>&lt;P&gt;I have a bunch of address points that all over the place and not in a line.&amp;nbsp; &amp;nbsp; I want to be able to clean these up and put them in a straight line.&amp;nbsp; &amp;nbsp; &amp;nbsp;I want to be able to highlight the address points I want to straighten and snap them to a line or just put them in a straight line.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things I have tried -&lt;/P&gt;&lt;P&gt;I have snaping them to a street line then moving them.&amp;nbsp; But that will not keep them evenly separated.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the Disperse tool, but some address points are to far out of the search area when setting minimum spacing.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the Align Features tool, but that doesn't seem to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions?&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jul 2023 18:42:58 GMT</pubDate>
    <dc:creator>NeilSexton</dc:creator>
    <dc:date>2023-07-19T18:42:58Z</dc:date>
    <item>
      <title>Aligning random Address Points to a straight line.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/aligning-random-address-points-to-a-straight-line/m-p/1309700#M71227</link>
      <description>&lt;P&gt;I have a bunch of address points that all over the place and not in a line.&amp;nbsp; &amp;nbsp; I want to be able to clean these up and put them in a straight line.&amp;nbsp; &amp;nbsp; &amp;nbsp;I want to be able to highlight the address points I want to straighten and snap them to a line or just put them in a straight line.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things I have tried -&lt;/P&gt;&lt;P&gt;I have snaping them to a street line then moving them.&amp;nbsp; But that will not keep them evenly separated.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the Disperse tool, but some address points are to far out of the search area when setting minimum spacing.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the Align Features tool, but that doesn't seem to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions?&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 18:42:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/aligning-random-address-points-to-a-straight-line/m-p/1309700#M71227</guid>
      <dc:creator>NeilSexton</dc:creator>
      <dc:date>2023-07-19T18:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Aligning random Address Points to a straight line.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/aligning-random-address-points-to-a-straight-line/m-p/1309830#M71237</link>
      <description>&lt;P&gt;Here's one way to do it:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Copy/paste the script into your ArcGIS Pro Python Window and execute. This will define a function 'straighten_points'.&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="python"&gt;import numpy

def straighten_points(layer, fit_degree=1):
    """Snaps all (selected) points in a layer to a regression line. This edits the input layer!
    
    layer: layer name (str) or layer object (arcpy.mp.Layer)
    fit_degree (int): degree of the polynomal fit, defaults to 1 (linear regression)
    """ 
    sr = arcpy.Describe(layer).spatialReference
    # extract point coordinates
    points = [r[0].firstPoint for r in arcpy.da.SearchCursor(layer, ["SHAPE@"])]
    x = [p.X for p in points]
    y = [p.Y for p in points]
    # polynomial fit
    coef = numpy.polyfit(x, y, fit_degree)
    polynom = numpy.poly1d(coef)
    # construct fit line geometry
    fit_xy = [
        [x_, polynom(x_)]
         for x_ in numpy.linspace(min(x) - 1000, max(x) + 1000, 100)
    ]
    fit_points = [arcpy.Point(fx, fy) for fx, fy in fit_xy]
    line = arcpy.Polyline(arcpy.Array(fit_points), spatial_reference=sr)
    # snap points to regression line geometry and update layer
    with arcpy.da.UpdateCursor(layer, ["SHAPE@"]) as cursor:
        for  p, in cursor:
            new_p = line.snapToLine(p)
            cursor.updateRow([new_p])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Select the points you want to straighten&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Run the function. Using 1 does a linear regression, which should be fine for straight road segments. For curves, you could try 2 or higher degrees, but remember that using this function will edit the layer, so make a backup.&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="python"&gt;straighten_points("NameOfYourLayer", 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1689805777072.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75813iA6FB3D31E7BBFEF8/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1689805777072.png" alt="JohannesLindner_0-1689805777072.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After (northern road: fit_degree = 1, southern road: fit_degree = 2:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1689805838236.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75814i77CCBF99EE56B325/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_1-1689805838236.png" alt="JohannesLindner_1-1689805838236.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 22:31:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/aligning-random-address-points-to-a-straight-line/m-p/1309830#M71237</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-07-19T22:31:34Z</dc:date>
    </item>
  </channel>
</rss>

