I am trying to update our street center line information that does not have the "From Street" or "To Street" field populated. All our data has is "On Street". Is there an "easy" way to write a script or is there a set of tools that can be used to help populate this information automatically?
Hi Kevin Cross and Joe Borgione ,
So here goes... As I mentioned before I used the MultiPart to SinglePart tool to create a featureclass without multipart features. The reason for this is that there can be several line parts in a single feature, and when I extract the firstPoint and lastPoint of the Polyline it will not represent the start and end of the street.
After doing that I noticed that there were some cases (actually quite a number) where the same street continuous with another feature. Dissolve with the unsplit and without creating multiparts could help but this would make you loose some attributes that might be relevant.
So, I ordered the features on the FullName and checked the cases where in an edit session I could merge the feature into one feature. There are some very challenging cases in your data Kevin.
Some of them will simply have not result:
In this case Webster Ln in the middle would have from and to street with the same name and those results are filtered out.
There where some multipart features created in the manual process and if the parts are not in the correct order (and in some case there aren't) it will not find the correct start and end points of the line and because of that not find a from and/or to feature within the defined search tolerance.
Also the fact that there are a substantial number of streets without a FullName makes things a bit more complicated, When a candidate is found that has no name it is filtered out of the results and may result in the intersecting street not to have a from or to street.
There are however, a number of case that should have a result, but do not have any. This would require some serious debugging to understand what is happening in those cases in order to understand what needs to be changed in the code to get results there without the possibility to loose results elsewhere.
After the editing the data manually I ended up with 289 streets and and 212 have a from and/or to street as result. Some of the 77 cases may not have a from or to street, but there are cases, as mentioned before, that should have a result.
For now let's have a look at the code and I will attache the resulting featureclass for you to revise.
<SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN> <SPAN class="comment token"># Name: from_to_street.py</SPAN> <SPAN class="comment token"># Purpose:</SPAN> <SPAN class="comment token">#</SPAN> <SPAN class="comment token"># Author: xbakker</SPAN> <SPAN class="comment token">#</SPAN> <SPAN class="comment token"># Created: 21/06/2017</SPAN> <SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\Streets\GeoNet Street Sample.gdb\LebStreetSample_MP2SP'</SPAN> fld_fullname <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Fullname'</SPAN> fld_from <SPAN class="operator token">=</SPAN> <SPAN class="string token">'From_Street'</SPAN> fld_to <SPAN class="operator token">=</SPAN> <SPAN class="string token">'To_Street'</SPAN> tolerance <SPAN class="operator token">=</SPAN> <SPAN class="number token">5</SPAN> <SPAN class="comment token"># 5 feet distance tolerance for finding intersections</SPAN> min_angle <SPAN class="operator token">=</SPAN> <SPAN class="number token">45</SPAN> <SPAN class="comment token"># to detect angle intersections</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 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_fullname<SPAN class="punctuation token">)</SPAN> dct <SPAN class="operator 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> <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> r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</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="keyword token">print</SPAN> <SPAN class="string token">"dict filled..."</SPAN> cnt <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> dct_res <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN> <SPAN class="comment token"># fill with results</SPAN> <SPAN class="keyword token">for</SPAN> oid<SPAN class="punctuation token">,</SPAN> lst <SPAN class="keyword token">in</SPAN> dct<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> polyline <SPAN class="operator token">=</SPAN> lst<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> full_name <SPAN class="operator token">=</SPAN> lst<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> full_name <SPAN class="operator token">!=</SPAN> <SPAN class="string token">' '</SPAN><SPAN class="punctuation token">:</SPAN> cnt <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="keyword token">if</SPAN> cnt <SPAN class="operator token">%</SPAN> <SPAN class="number token">50</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Processing:"</SPAN><SPAN class="punctuation token">,</SPAN> cnt from_pnt <SPAN class="operator token">=</SPAN> polyline<SPAN class="punctuation token">.</SPAN>firstPoint to_pnt <SPAN class="operator token">=</SPAN> polyline<SPAN class="punctuation token">.</SPAN>lastPoint <SPAN class="comment token"># get a list of candidates for from and to points</SPAN> from_oids <SPAN class="operator token">=</SPAN> SelectFromToCandidates<SPAN class="punctuation token">(</SPAN>oid<SPAN class="punctuation token">,</SPAN> full_name<SPAN class="punctuation token">,</SPAN> from_pnt<SPAN class="punctuation token">,</SPAN> dct<SPAN class="punctuation token">,</SPAN> tolerance<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> to_oids <SPAN class="operator token">=</SPAN> SelectFromToCandidates<SPAN class="punctuation token">(</SPAN>oid<SPAN class="punctuation token">,</SPAN> full_name<SPAN class="punctuation token">,</SPAN> to_pnt<SPAN class="punctuation token">,</SPAN> dct<SPAN class="punctuation token">,</SPAN> tolerance<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">" - before filter: "</SPAN><SPAN class="punctuation token">,</SPAN> full_name<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">,</SPAN> from_oids<SPAN class="punctuation token">,</SPAN> to_oids <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>from_oids<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> from_oids <SPAN class="operator token">=</SPAN> FilterListOnAngles<SPAN class="punctuation token">(</SPAN>dct<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">,</SPAN> from_oids<SPAN class="punctuation token">,</SPAN> min_angle<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>to_oids<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> to_oids <SPAN class="operator token">=</SPAN> FilterListOnAngles<SPAN class="punctuation token">(</SPAN>dct<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">,</SPAN> to_oids<SPAN class="punctuation token">,</SPAN> min_angle<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">" - after filter: "</SPAN><SPAN class="punctuation token">,</SPAN> full_name<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">,</SPAN> from_oids<SPAN class="punctuation token">,</SPAN> to_oids <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>from_oids<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> from_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> from_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">', '</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>dct<SPAN class="punctuation token">[</SPAN>o<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> o <SPAN class="keyword token">in</SPAN> from_oids<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>to_oids<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> to_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> to_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">', '</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>dct<SPAN class="punctuation token">[</SPAN>o<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> o <SPAN class="keyword token">in</SPAN> to_oids<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> from_streets <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">' '</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">' , '</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> from_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">if</SPAN> to_streets <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">' '</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">' , '</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> to_streets <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">print</SPAN> oid<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" - From:"</SPAN><SPAN class="punctuation token">,</SPAN> from_streets<SPAN class="punctuation token">,</SPAN> from_oids <SPAN class="keyword token">print</SPAN> oid<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" - To :"</SPAN><SPAN class="punctuation token">,</SPAN> to_streets<SPAN class="punctuation token">,</SPAN> to_oids dct_res<SPAN class="punctuation token">[</SPAN>oid<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>oid<SPAN class="punctuation token">,</SPAN> from_streets<SPAN class="punctuation token">,</SPAN> to_streets<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"update cursor..."</SPAN> cnt <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> updates <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'OID@'</SPAN><SPAN class="punctuation token">,</SPAN> fld_from<SPAN class="punctuation token">,</SPAN> fld_to<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> curs<SPAN class="punctuation token">:</SPAN> cnt <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> oid <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> oid <SPAN class="keyword token">in</SPAN> dct_res<SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> dct_res<SPAN class="punctuation token">[</SPAN>oid<SPAN class="punctuation token">]</SPAN> curs<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>tuple<SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> updates <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="keyword token">if</SPAN> cnt <SPAN class="operator token">%</SPAN> <SPAN class="number token">50</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="string token">"processing row:"</SPAN><SPAN class="punctuation token">,</SPAN> cnt<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" - updates:"</SPAN><SPAN class="punctuation token">,</SPAN> updates <SPAN class="keyword token">def</SPAN> <SPAN class="token function">FilterListOnAngles</SPAN><SPAN class="punctuation token">(</SPAN>dct<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">,</SPAN> candidates<SPAN class="punctuation token">,</SPAN> angle_tolerance<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> polyline <SPAN class="operator token">=</SPAN> dct<SPAN class="punctuation token">[</SPAN>oid<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> oids_ok <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> candidate <SPAN class="keyword token">in</SPAN> candidates<SPAN class="punctuation token">:</SPAN> polyline_cand <SPAN class="operator token">=</SPAN> dct<SPAN class="punctuation token">[</SPAN>candidate<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> ValidateAngle<SPAN class="punctuation token">(</SPAN>polyline<SPAN class="punctuation token">,</SPAN> polyline_cand<SPAN class="punctuation token">,</SPAN> angle_tolerance<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> oids_ok<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>candidate<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> oids_ok <SPAN class="keyword token">def</SPAN> <SPAN class="token function">ValidateAngle</SPAN><SPAN class="punctuation token">(</SPAN>polyline1<SPAN class="punctuation token">,</SPAN> polyline2<SPAN class="punctuation token">,</SPAN> angle_tolerance<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># get start segment and end segment</SPAN> start1 <SPAN class="operator token">=</SPAN> polyline1<SPAN class="punctuation token">.</SPAN>segmentAlongLine<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> end1 <SPAN class="operator token">=</SPAN> polyline1<SPAN class="punctuation token">.</SPAN>segmentAlongLine<SPAN class="punctuation token">(</SPAN>polyline1<SPAN class="punctuation token">.</SPAN>length<SPAN class="number token">-1</SPAN><SPAN class="punctuation token">,</SPAN> polyline1<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># sr = polyline1.spatialReference</SPAN> <SPAN class="comment token"># determine distance start segment and end segment to intersecting line</SPAN> d_start <SPAN class="operator token">=</SPAN> start1<SPAN class="punctuation token">.</SPAN>distanceTo<SPAN class="punctuation token">(</SPAN>polyline2<SPAN class="punctuation token">)</SPAN> d_end <SPAN class="operator token">=</SPAN> end1<SPAN class="punctuation token">.</SPAN>distanceTo<SPAN class="punctuation token">(</SPAN>polyline2<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> d_start <SPAN class="operator token"><</SPAN> d_end<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># start is closer to intersecting line</SPAN> pntg <SPAN class="operator token">=</SPAN> polyline2<SPAN class="punctuation token">.</SPAN>queryPointAndDistance<SPAN class="punctuation token">(</SPAN>polyline1<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> seg1 <SPAN class="operator token">=</SPAN> start1 <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># end is closer to intersecting line</SPAN> pntg <SPAN class="operator token">=</SPAN> polyline2<SPAN class="punctuation token">.</SPAN>queryPointAndDistance<SPAN class="punctuation token">(</SPAN>polyline1<SPAN class="punctuation token">.</SPAN>lastPoint<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> seg1 <SPAN class="operator token">=</SPAN> end1 <SPAN class="comment token"># get position of projected point on intersecting line</SPAN> distance_along <SPAN class="operator token">=</SPAN> polyline2<SPAN class="punctuation token">.</SPAN>measureOnLine <SPAN class="punctuation token">(</SPAN>pntg<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># and extract segment</SPAN> seg2 <SPAN class="operator token">=</SPAN> polyline2<SPAN class="punctuation token">.</SPAN>segmentAlongLine<SPAN class="punctuation token">(</SPAN>max<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>distance_along <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> min<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>distance_along <SPAN class="operator token">+</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> polyline2<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"seg1.length"</SPAN><SPAN class="punctuation token">,</SPAN> seg1<SPAN class="punctuation token">.</SPAN>length <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"seg2.length"</SPAN><SPAN class="punctuation token">,</SPAN> seg2<SPAN class="punctuation token">.</SPAN>length <SPAN class="comment token"># compare</SPAN> compare_angles <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>seg1<SPAN class="punctuation token">,</SPAN> seg2<SPAN class="punctuation token">]</SPAN> angle_segs <SPAN class="operator token">=</SPAN> GetAngleSegments<SPAN class="punctuation token">(</SPAN>compare_angles<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"angle_segs 1"</SPAN><SPAN class="punctuation token">,</SPAN> angle_segs <SPAN class="keyword token">while</SPAN> angle_segs <SPAN class="operator token"><</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> angle_segs <SPAN class="operator token">+=</SPAN> <SPAN class="number token">180</SPAN> <SPAN class="keyword token">while</SPAN> angle_segs <SPAN class="operator token">></SPAN> <SPAN class="number token">360</SPAN><SPAN class="punctuation token">:</SPAN> angle_segs <SPAN class="operator token">-=</SPAN> <SPAN class="number token">360</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"angle_segs 2"</SPAN><SPAN class="punctuation token">,</SPAN> angle_segs <SPAN class="keyword token">if</SPAN> IsBetween<SPAN class="punctuation token">(</SPAN>angle_segs<SPAN class="punctuation token">,</SPAN> angle_tolerance<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">180</SPAN> <SPAN class="operator token">-</SPAN> angle_tolerance<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">or</SPAN> IsBetween<SPAN class="punctuation token">(</SPAN>angle_segs<SPAN class="punctuation token">,</SPAN> angle_tolerance <SPAN class="operator token">+</SPAN> <SPAN class="number token">180</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">360</SPAN> <SPAN class="operator token">-</SPAN> angle_tolerance<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"ValidateAngle ERROR @ OID:"</SPAN><SPAN class="punctuation token">,</SPAN> oid <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">IsBetween</SPAN><SPAN class="punctuation token">(</SPAN>val<SPAN class="punctuation token">,</SPAN> val_min<SPAN class="punctuation token">,</SPAN> val_max<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> val <SPAN class="operator token">>=</SPAN> val_min <SPAN class="operator token">and</SPAN> val <SPAN class="operator token"><=</SPAN> val_max<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">GetAngleSegments</SPAN><SPAN class="punctuation token">(</SPAN>segments<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> angles <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> seg <SPAN class="keyword token">in</SPAN> segments<SPAN class="punctuation token">:</SPAN> pntg1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>seg<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">,</SPAN> seg<SPAN class="punctuation token">.</SPAN>spatialReference<SPAN class="punctuation token">)</SPAN> pntg2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>seg<SPAN class="punctuation token">.</SPAN>lastPoint<SPAN class="punctuation token">,</SPAN> seg<SPAN class="punctuation token">.</SPAN>spatialReference<SPAN class="punctuation token">)</SPAN> angle <SPAN class="operator token">=</SPAN> GetAngle<SPAN class="punctuation token">(</SPAN>pntg1<SPAN class="punctuation token">,</SPAN> pntg2<SPAN class="punctuation token">)</SPAN> angles<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>angle<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#print "angles", angles</SPAN> angle_between <SPAN class="operator token">=</SPAN> angles<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">-</SPAN> angles<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">return</SPAN> angle_between <SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> None <SPAN class="keyword token">def</SPAN> <SPAN class="token function">GetAngle</SPAN><SPAN class="punctuation token">(</SPAN>pntg1<SPAN class="punctuation token">,</SPAN> pntg2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'''determine angle of line based on start and end points geometries'''</SPAN> <SPAN class="keyword token">return</SPAN> pntg1<SPAN class="punctuation token">.</SPAN>angleAndDistanceTo<SPAN class="punctuation token">(</SPAN>pntg2<SPAN class="punctuation token">,</SPAN> method<SPAN class="operator token">=</SPAN><SPAN class="string token">'PLANAR'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">SelectFromToCandidates</SPAN><SPAN class="punctuation token">(</SPAN>cur_oid<SPAN class="punctuation token">,</SPAN> cur_full_name<SPAN class="punctuation token">,</SPAN> pnt<SPAN class="punctuation token">,</SPAN> dct<SPAN class="punctuation token">,</SPAN> tolerance<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> oids <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> pntg <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>pnt<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> oid<SPAN class="punctuation token">,</SPAN> lst <SPAN class="keyword token">in</SPAN> dct<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> full_name <SPAN class="operator token">=</SPAN> lst<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> oid <SPAN class="operator token">!=</SPAN> cur_oid<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># don't include the current polyline in results</SPAN> <SPAN class="keyword token">if</SPAN> full_name <SPAN class="operator token">!=</SPAN> cur_full_name<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># don't include street with the same name</SPAN> polyline <SPAN class="operator token">=</SPAN> lst<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> polyline<SPAN class="punctuation token">.</SPAN>distanceTo<SPAN class="punctuation token">(</SPAN>pntg<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><=</SPAN> tolerance<SPAN class="punctuation token">:</SPAN> oids<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>oid<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> list<SPAN class="punctuation token">(</SPAN>set<SPAN class="punctuation token">(</SPAN>oids<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN> main<SPAN class="punctuation token">(</SPAN><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></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><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>
So let's see what happens in the script (and to be honest, I'm not very happy with it as it is, since there is a lot of room for enhancement).
This is basically what goes on in the script.
Attached you will find the result.
To help solve this, what sort of information is in "On Street"? Is the "To" and "From" address range there?
Addressing
Chris Donohue, GISP
a blog from a few years ago
https://blogs.esri.com/esri/arcgis/2013/02/11/streetintersectionlist/
I am sure there are other references but the mechanics will undoubtedly depend on your existing data
Below is a sample of what the data looks like. I inherited this and am trying to fix it! Currently nothing has been filled out in the "From Street or the To Street".
All our data has is "On Street"
There does not appear to be an "On Street" field in the example. Can you elaborate on what is in the "On Street" field currently? Does it contain the street address ranges? If so, it may be possible to write a script to extract out the "To Street" and "From Street" values from the "On Street" field. However, we will need to be able to see the data and how it is arranged in the "On Street" field to evaluate this and come up with the correct code.
If the "On Street" field does not contain the range and there are no other fields in the data that contain the street address range information, then the challenge will instead be to derive the ranges. This may be possible if you have other data. For example, if you have address range data in an Intersection points layer, it can be spatial-joined to the lines and then calculated across. Again, it will depend on what data you have and how it is arranged.
Admittedly I'm nothing of a programmer, but having hacked on this for a few minutes, I don't see it as 'easy'. You'll need to iterate through the from nodes of each street segment, select those streets (sans the active street) that intersect that from node and then determine a method to choose which one, if they are different, goes in the From Street attribute. Repeat the process for the To Nodes.
Maybe Dan_Patterson or dkwiens_edi or xander_bakker can take it from here....
Joe... attachment? or something?
kevin.cross , if you are willing to share a sample of your data, I'm sure we can have a look at it to see what can be done.
Dan- I was just working through it manually, trying to figure out the steps/procedures.
Dan_Patterson
Xander, What would be the best way to get you the data?
My bad, the "On Street" Field would be the "Full Name" Field in the example above.
Hi Kevin Cross , you could select a subset of your data, export it to a new File Geodatabase, and ZIP that fgdb. Make sure it is a representative subset of the entire dataset.
To attach the ZIP you can either edit the original post or to this comment and use the advanced editor (link upper right corner when replying to the thread) which will reveal the Attach option in the lower left corner of the advanced editor.
Hi Kevin Cross and jborgion , did you have a chance to play with the code?
Sorry Xander, haven't had the opportunity, but I'd like to study the code as a lesson. (xander_bakker)
If you need some additional explanation, just let me know.
Sorry for the late reply. I've been on vacation and we've been in the process of changing vendors for our GIS hosting. I ran the script on my full data set and it looks like it did a great job breaking things where I needed them to. There looks to be some clean up on things, but that's to be expected. I appreciate your help on this. This has saved me a lot of man hours doing it manually!
Hi Kevin Cross , glad it you found the script useful. It might be necessary to do some editing on the data before and afterwards, since it does not account for all situations. Did you catch any other inconveniences? In case the script solved your question, please mark that post as the correct answer.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.