Hi,
I have a set of points (as shown in the picture). I want to join them and assign unique id to them. How this can be achieved using python or Model Builder on Arcmap 10.5?
And join the like the below picture :
Thanks in Advance.
I just played with just using the distance (not the direction) to define where to start a new line, and the results are not too bad I guess. See code below:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Esri\GeoNet\GIS_RIVER\23_elevation.shp'</SPAN> fld_memo <SPAN class="operator token">=</SPAN> <SPAN class="string token">'TxtMemo'</SPAN> fc_out <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Esri\GeoNet\GIS_RIVER\3D_lines_v06.shp'</SPAN> fld_id <SPAN class="operator token">=</SPAN> <SPAN class="string token">'LineID'</SPAN> fld_zmin <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Z_min'</SPAN> fld_zmax <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Z_max'</SPAN> id_format <SPAN class="operator token">=</SPAN> <SPAN class="string token">'CS-{}'</SPAN> tolerance <SPAN class="operator token">=</SPAN> <SPAN class="number token">150</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'OID@'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">,</SPAN> fld_memo<SPAN class="punctuation token">)</SPAN> lst_data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> float<SPAN class="punctuation token">(</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> r <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># create output featureclass</SPAN> sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>spatialReference ws<SPAN class="punctuation token">,</SPAN> fc_name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureclass_management<SPAN class="punctuation token">(</SPAN>ws<SPAN class="punctuation token">,</SPAN> fc_name<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POLYLINE"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ENABLED"</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> fld_id<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">25</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> fld_zmin<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"DOUBLE"</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> fld_zmax<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"DOUBLE"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># insert cursor</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">,</SPAN> fld_id<SPAN class="punctuation token">,</SPAN> fld_zmin<SPAN class="punctuation token">,</SPAN> fld_zmax<SPAN class="punctuation token">)</SPAN> cnt_id <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs<SPAN class="punctuation token">:</SPAN> lst_lines <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> lst_pnts <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> len<SPAN class="punctuation token">(</SPAN>lst_data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"i:{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> lst_cur <SPAN class="operator token">=</SPAN> lst_data<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> lst_prev <SPAN class="operator token">=</SPAN> lst_data<SPAN class="punctuation token">[</SPAN>i<SPAN class="number token">-1</SPAN><SPAN class="punctuation token">]</SPAN> pntg_cur <SPAN class="operator token">=</SPAN> lst_cur<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> pntg_prev <SPAN class="operator token">=</SPAN> lst_prev<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> dist <SPAN class="operator token">=</SPAN> pntg_prev<SPAN class="punctuation token">.</SPAN>distanceTo<SPAN class="punctuation token">(</SPAN>pntg_cur<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> dist <SPAN class="operator token"><=</SPAN> tolerance<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># add to existing list</SPAN> pnt <SPAN class="operator token">=</SPAN> pntg_cur<SPAN class="punctuation token">.</SPAN>firstPoint z <SPAN class="operator token">=</SPAN> lst_cur<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> pnt<SPAN class="punctuation token">.</SPAN>Z <SPAN class="operator token">=</SPAN> z lst_pnts<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>pnt<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">" - create and store line and add point to new list..."</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create and store line and add point to new list</SPAN> <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>lst_pnts<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN>lst_pnts<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> zmin <SPAN class="operator token">=</SPAN> polyline<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ZMin zmax <SPAN class="operator token">=</SPAN> polyline<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ZMax <SPAN class="comment token"># lst_lines.append(polyline)</SPAN> cnt_id <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> line_id <SPAN class="operator token">=</SPAN> id_format<SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>cnt_id<SPAN class="punctuation token">)</SPAN> curs<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>polyline<SPAN class="punctuation token">,</SPAN> line_id<SPAN class="punctuation token">,</SPAN> zmin<SPAN class="punctuation token">,</SPAN> zmax<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># not enough points to create line</SPAN> <SPAN class="keyword token">pass</SPAN> pnt <SPAN class="operator token">=</SPAN> pntg_cur<SPAN class="punctuation token">.</SPAN>firstPoint z <SPAN class="operator token">=</SPAN> lst_cur<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> pnt<SPAN class="punctuation token">.</SPAN>Z <SPAN class="operator token">=</SPAN> z lst_pnts <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>pnt<SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The resulting 3D polylines also contain Z min and Z max values. The order of the ID's will follow the order of the points, not necessarily from the north to the south.
I will attach the resulting shape file for you to have a look and inspect if this comes anything near to what you are looking for.
I notice that the only attribute the points have, is a text field with a numeric value (probably depth).There is no "line identifier" and one should apply a distance calculation to define which points are to be combined into a line. In order to write a process that will create the lines, there are a number of challenges that you will face and some data quality issues that I noticed:
The red circle top center shows two points that have very different values. The white point probably has a wrong value. In the lower part the ellipse shows a larger distance (up to 150 meters) between the points that would probably need to be connected or are part of the same line.
At the same time the profile lines sometimes are close together which will make it harder to distinguish the lines and assign points to the correct line.
... and in some case the lines cross:
This will complicate the process.
Now the order of the points (FID) seems to follow the order in which the data was collected and that will help in defining the lines:
We can do something with direction and distance between consecutive points to define the lines.
I've shared it. PFA.
Sorry I didn't get it.
Yes you're correct. How can I attach my data here? Couldn't find any option.
May we assume that the points do not yet contain an identifier (like "CS-1")? does the process has to figure out which points to combine into a single line? If so, that would be the first challenge. The second challenge is to define in which order the points need to be connected. For the first challenge it would help to know what licence level of ArcMap or Pro you have (Advanced would allow the usage of tools like Near). Are you willing to share (a part of) your data?
I 'd prefer to read this thread Create a line from points using attributes , I think you will get good answer.
You could... but how many do you have? 10's, 100's 1000's? and is this a one-off? because there are a variety of clustering point data and the spatial statistics toolset has some, but implementations in python/scipy/etc can be used as well depending on the complexity of the problem. I guess you would have to weigh the time to do this manually versus the time to implemented in an automated fashion.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.