<?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 Longest Line Within a Polygon in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198014#M6775</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to model the longest possible line within a (irregular ou regular) polygon feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The line should be a 100% inside polygon!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Someone knows a tool for that task?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using ArcGIS for Desktop 10.2.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Tks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Rafael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Apr 2014 20:45:30 GMT</pubDate>
    <dc:creator>RafaelRuas_Martins</dc:creator>
    <dc:date>2014-04-16T20:45:30Z</dc:date>
    <item>
      <title>Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198014#M6775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to model the longest possible line within a (irregular ou regular) polygon feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The line should be a 100% inside polygon!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Someone knows a tool for that task?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using ArcGIS for Desktop 10.2.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Tks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Rafael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 20:45:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198014#M6775</guid>
      <dc:creator>RafaelRuas_Martins</dc:creator>
      <dc:date>2014-04-16T20:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198015#M6776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It sounds like you are wanting to select the longest line feature which is completely within a specific polygon.&amp;nbsp; Are you looking for a model, a python script, or the instructions for how to do this manually within ArcMap?&amp;nbsp; In general, I think you would need several tools to address this requirement.&amp;nbsp; Here are the high-level steps:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;** Assumes you have a line feature class and a polygon feature class **&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Select a single polygon feature, either manually or based on some attribute criteria.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Select by Location: select lines from the line feature class which are completely within the polygon feature class (the previously-selected polygon from the step above will honor the selection set of 1 feature)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Find the longest feature - this can be handled multiple ways:&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Select by Attribute: select lines from the currently-selected features of the line feature class using MAX(SHAPE.LENGTH) or MAX(SHAPE_LENGTH) depending on your type of data source&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Open the attribute table of the line feature class, choose the option at the bottom to view only the selected features, and sort the SHAPE.LENGTH field (or SHAPE_LENGTH field) in descending order&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Create a new field of DOUBLE (38,8) type and use the Calculate Geometry tool (right click the field from the attribute table) or the Calculate Field geoprocessing tool to calculate the true length of the line features based on the units from the coordinate system of the feature class.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;BR /&gt;&lt;SPAN&gt;There are likely more ways to handle step 3 than the bulleted options I specified above.&amp;nbsp; Let me know more about your requirements and I can be more specific about the approach.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 23:59:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198015#M6776</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2014-04-16T23:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198016#M6777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just generate all the lines by connecting vertex pairs of the polygon and find the longest.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Try to avoid iterating around each point combination, think of a process that handles all lines at once.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can leave out the first and last pair of each point iteration because they will be sides, and you only have to do half because the direction does not matter. You can use python collection permutations to get a unique list of pairs. Then turn them into a list of polylines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Because a polygon may not be regular, say a banana shape, then you will need a filter to exclude potential lines crossing the boundary for my simple first stab, but there is a test [ a_poly.overlaps(a_line) ] for that in shape objects. Even better you could test them all in one step, using SelectLayerByLocation(..."WITHIN_CLEMENTINI"...) to select remaining candidates to find the max(length). All the tools will take a geometry list instead of a featureclass so it is fast, in memory and efficient enough to iterate over a large number of polygons.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Apr 2014 22:37:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198016#M6777</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2014-04-27T22:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198017#M6778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I used to do this by building a near table on the vertices and &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;selecting the pair with the maximum distance; noting that an&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;isocolese triangle would have two such pairs, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so attention paid to getting the correct pair&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(and not the two points across the base)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;was worthwhile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is a new tool called &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MinimumBoundingGeometry In the Management toolbox under Features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The CONVEX_HULL option adds (among others) the fields&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MBG_Length�??The longest distance between any two vertices of the convex hull; these vertices are called antipodal pairs or antipodal points. (It may be found between more than one pair of vertices, but the first found will be used.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MBG_APodX1�??The x coordinate of the first point of the antipodal pairs. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MBG_APodY1�??The y coordinate of the first point of the antipodal pairs. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MBG_APodX2�??The x coordinate of the second point of the antipodal pairs. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MBG_APodY2�??The y coordinate of the second point of the antipodal pairs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does NOT, however, test for interiority... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does sound like constructing a set of geometry object lines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;testing them WITHIN_CLEMENTINI,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and picking the longest may be what you have to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Apr 2014 11:39:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198017#M6778</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-04-28T11:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198018#M6779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I couldn't resist hacking up a script to see what happened.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;There were of course a few issues.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The MakeFeatureLayer tool would not take a geometry list, so I resorted to using in_memory featureclasses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The WITHIN_CLEMENTINI query worked fine interactively in ArcMap but chokes on a polygon with more than a dozen vertices in a script. So a new workaround is needed for that. I test each line as it is generated, and then I could also test its length cumulatively so would only have to test for contains if it is a replacement candidate and I only need to keep the longest current line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This reduced the time per polygon to about 2 seconds. Fairly slow, but it will handle very complex polygons now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Second Hack:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#-------------------------------------------------------------------------------
# Name:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LongestLine.py
# Purpose:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; find the longest inside line across a polygon
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Limitations: only single part polygons, no donuts
# Author:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kimo
#
# Created:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29/04/2014
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/04/2014 changed crossing test to each features
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exclude triangles (use trigonometry for this degenerate case)
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; longest line only tested between vertices may need to densify first
#
# Copyright:&amp;nbsp;&amp;nbsp; (c) kimo 2014
# Licence:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Creative Commons 3.0 New Zealand
#-------------------------------------------------------------------------------
import arcpy
import sys
import itertools
import datetime
gdb = sys.argv[1]
fcPoly = 'forest'
fcOut = 'fan'
arcpy.env.workspace = gdb
arcpy.env.overwriteOutput = True
begintime = datetime.datetime.now()
desc = arcpy.Describe(fcPoly)
sr = desc.spatialReference
arcpy.env.outputCoordinateSystem = sr
if arcpy.Exists(fcOut):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.Delete(fcOut)
arcpy.management.CreateFeatureclass(gdb,fcOut,"POLYLINE",spatial_reference=sr)
arcpy.management.AddField(fcOut,"ORIGID","LONG")
icur = arcpy.da.InsertCursor(fcOut,['ORIGID','SHAPE@'])
with arcpy.da.SearchCursor(fcPoly,["OBJECTID","SHAPE@"]) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gPoly = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Begin id {} parts {} points {} type {}".format(id,gPoly.partCount,gPoly.pointCount,gPoly.type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gPoly.partCount == 1 and gPoly.pointCount &amp;gt; 4: # exclude triangles
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; starttime = datetime.datetime.now()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstV = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for part in gPoly:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for v in part:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstV.append(v)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oCount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rCount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxlength = -1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # use itertools to get unique combinations of pairs
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # leave in lines coincident with boundary segments
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # because they will always be less than max length if &amp;gt; triangle
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for vPair in itertools.combinations(lstV[:-1],2): # exclude last duplicated poly vertex
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aLine = arcpy.Polyline(arcpy.Array(vPair),sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # dont even bother doing spatial test if already shorter for speed
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if aLine.length &amp;gt; maxlength :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gPoly.contains(aLine): # not lines crossing edges
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mLine = aLine
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxlength = aLine.length
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCount+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oCount+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rCount+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Max swapped {} Overlap rejects {} Already shorter {}".format(pCount,oCount,rCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rec = (id,mLine)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; icur.insertRow(rec)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg = "{} {} time {}".format(id,maxlength,datetime.datetime.now() - starttime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print msg
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(msg)

del icur

print "done",datetime.datetime.now() - begintime

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added the original Objectid to be able to relate back to each polygon, geometries do not allow me to keep the original ID so I keep it as a python variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:53:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198018#M6779</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T09:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198019#M6780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since writing my solution I have found an ArcView 3.x solution that shows I have not covered all the cases. You could have a line running through a pair of vertices on a polygon with rentrant sides that extent out each way to the polygon boundary between vertices. I assumed that the longest line would always be coincident with vertices at the ends.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.jennessent.com/arcview/longest_lines.htm"&gt;http://www.jennessent.com/arcview/longest_lines.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well done to Jeff Jenness for handling this case in Avenue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jun 2014 02:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/198019#M6780</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2014-06-12T02:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1269237#M26771</link>
      <description>&lt;P&gt;EDIT: Thanks to&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/138359"&gt;@RobertEisler&lt;/a&gt;&amp;nbsp;for providing an example showing my transect_type = "PROPER" to be incorrect (the dotted black lines in all the pictures). As far as I am aware, the "BOUNDARY" option is still the optimal algorithm.&lt;/P&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1237"&gt;@KimOllivier&lt;/a&gt;&amp;nbsp;already noted, only checking vertex-to-vertex is not a sufficient algorithm to solve this problem.&lt;/P&gt;&lt;P&gt;Here is my approach. I am working under the assumption that the longest line will contain two vertices, but does not necessarily end at those two vertices. The user has the option to include the edges of shapes, or require the transect to be entirely internal [this is wrong, see EDIT at the top and replies down below] (red vs. dotted, respectively; sometimes these are the same). Multipart polygons only get one transect generated, so that's why a few shapes appear to be missing lines.&lt;/P&gt;&lt;P&gt;Shapes involving true curves have transects estimated using "densify" to generate actual vertices, so those are only close approximations. See the second screenshot, where the line should presumably be right up against the hole. Would be happy to hear suggestions on this.&lt;/P&gt;&lt;P&gt;These are test polygons, but on a real-world parcel dataset where the number of vertex-to-vertex combinations within a polygon can get into the hundreds of thousands, my version can take a while. Seemed like the bottleneck was converting every vertex coordinate combination to a Polyline object, so I would be very interested in optimizations if anyone has suggestions.&lt;/P&gt;&lt;P&gt;To summarize--script generates lines from all vertex-to-vertex pairs, extends those lines a bit (to cover cases like the castle shape at the top of the first below), clips them back to the polygon boundary, and then finds the longest in the list of lines within the given geometry.&lt;/P&gt;&lt;P&gt;EDIT: The "stopwatch as sw" module in this code is a custom time/message reporting module. Delete it or replace those with standard "print()" if anyone ends up using this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Transect line outputs." style="width: 703px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65633i75613F9EBFA5ACEB/image-size/large?v=v2&amp;amp;px=999" role="button" title="transect_lines.png" alt="Transect line outputs." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Transect line outputs.&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Longest transect through a feature composed of curved boundaries." style="width: 774px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65635i22132EE82EA1E6FF/image-size/large?v=v2&amp;amp;px=999" role="button" title="circle_transect.png" alt="Longest transect through a feature composed of curved boundaries." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Longest transect through a feature composed of curved boundaries.&lt;/span&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"""LONGEST TRANSECT"""
#---------------------------------------------------------------------------------------#
# IMPORTS
import collections
import itertools
import math
import os
import sys
import traceback
import uuid

import arcpy

import stopwatch as sw
#---------------------------------------------------------------------------------------#
# SETTINGS
arcpy.env.overwriteOutput = True
arcpy.env.workspace = **YOUR GEODATABASE PATH**
#---------------------------------------------------------------------------------------#
# INPUTS
polygons = "POLYGON"
polygon_id_fld = "POLY_GUID"
transects = "TRANSECT_BOUNDARY_TEST"

# Boundary = transect can be entire edge. Proper = transect must be witihin polygon.
transect_type = "BOUNDARY"  # ["BOUNDARY", "PROPER"]

# Only save the longest line for each polygon?
discard_nonmax_transects = False
#---------------------------------------------------------------------------------------#
# FUNCTIONS
def create_geom_dict(poly_fc, poly_id_fld, generalize=False):
    """Read poly geoms to information dict.
    returns {GUID: {POLYGON: &amp;lt;poly_obj&amp;gt;, POINTS: [&amp;lt;pnt_obj&amp;gt;, &amp;lt;pnt_obj&amp;gt;]}, ...}"""
    poly_geom_dict = collections.defaultdict(dict)

    with arcpy.da.SearchCursor(poly_fc, [poly_id_fld, "SHAPE@"]) as scurs:
        # For each row in the FC table (could be single, multi, have holes, etc.).
        for guid, geom in scurs:
            poly_geom_dict[guid]["POLYGON"] = geom

            # Curves to segments; generalize segments to speed process (?).
            if geom.hasCurves:
                geom = geom.generalize(1)
            elif generalize:
                geom = geom.generalize(0.5)

            # For each part of the geometry:
            for i, part in enumerate(geom, start=1):
                print(f"  Part {i}")
                # For each point in this part of the geometry:
                for j, point in enumerate(part, start=1):
                    if point:
                        poly_geom_dict[guid].setdefault("POINTS", []).append(point)
                    else:
                        print(f"    Point {j:&amp;gt;2}--Null point. Start interior ring.")

            stopwatch.stamptime(msg=f"READ {guid} GEOMETRY")

    return poly_geom_dict

def line_within_polygon(line, polygon, relation):
    """If the line is outside the polygon, or of zero length, return False."""
    if not line.within(polygon, relation=relation) or line.length == 0:
        return False
    else:
        return True
#---------------------------------------------------------------------------------------#
# MAIN
stopwatch = sw.Stopwatch()
stopwatch.starttime(msg="PROCESS STARTING")

spat_ref = arcpy.da.Describe(polygons)["spatialReference"].factoryCode

poly_geom_dict = create_geom_dict(poly_fc=polygons, poly_id_fld=polygon_id_fld)

# Remove duplicate points; added due to closing geoms, maybe rings?
for guid in poly_geom_dict:
    unique_coors = set((p.X, p.Y) for p in poly_geom_dict[guid]["POINTS"])
    poly_geom_dict[guid]["POINTS"] = [arcpy.Point(*coor) for coor in unique_coors]

# Create transect FC. Add Fields.
trans_fc = arcpy.management.CreateFeatureclass(out_path=arcpy.env.workspace,
                                out_name=transects,
                                geometry_type="POLYLINE",
                                spatial_reference=spat_ref)
flds = [("POLY_GUID", "GUID"), ("LINE_GUID", "GUID"), ("LONGEST", "TEXT")]
for fld_name, fld_type in flds:
    arcpy.management.AddField(in_table=trans_fc, field_name=fld_name,
                              field_type=fld_type, field_length=1)

stopwatch.stamptime(msg="CREATED TRANSECT FC\n")

# Walk through the dictionary making lines:
# These lists house intermediate geometries; review during testing.
test_multiparts = []
test_extensions = []
for guid, geom_dict in poly_geom_dict.items():
    stopwatch.stamptime(msg=f"PROCESSING STARTED ON {guid}")

    vert_pairs = len(list(itertools.combinations(iterable=geom_dict["POINTS"], r=2)))
    print(f"VERTEX PAIRS TO PROCESS: {vert_pairs}")

    line_geoms = []
    for p1, p2 in itertools.combinations(iterable=geom_dict["POINTS"], r=2):
        line = arcpy.Polyline(inputs=arcpy.Array([p1, p2]))

        # WITHIN POLYGON
        poly_geom = geom_dict["POLYGON"]
        if not line_within_polygon(line, poly_geom, relation=transect_type):
            continue

        # EXTEND LINE
        new_pnts = arcpy.Array()

        # Extension distance is somewhat arbitrary. Extend line 1/4 perimeter
        #   of the Extent object. Seems to be enough (?).
        extend_distance = poly_geom.extent.polygon.boundary().length / 4

        angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)
        new_pnts.add(arcpy.Point(p1.X - extend_distance * math.cos(angle),
                                 p1.Y - extend_distance * math.sin(angle)))
        new_pnts.add(arcpy.Point(p2.X + extend_distance * math.cos(angle),
                                 p2.Y + extend_distance * math.sin(angle)))

        # CLIP TO POLYGON
        extended_line = arcpy.Polyline(new_pnts)
        clipped_line = extended_line.intersect(poly_geom, 2)
        test_extensions.append(extended_line)

        # Get all points on line. &amp;gt;2 possible from edge intersections.
        merged_array = arcpy.Array()
        for part in clipped_line:
            for point in part:
                merged_array.add(point)

        # Sort points along X, then Y. Since the line is straight, we don't
        #   need to do linear referencing or anything. Keep first/last only.
        # Removes needless vertices and reorders points on line.
        sort_arr = arcpy.Array(sorted(merged_array, key=lambda p: (p.X, p.Y)))
        full_polyline = arcpy.Polyline(arcpy.Array([sort_arr[0], sort_arr[-1]]))
        test_multiparts.append(full_polyline)

        # If line extends over white space between multipart polygons.
        # isclose() is used here for float precision issues.
        if not math.isclose(full_polyline.length, clipped_line.length):
            # Retain parts of extended lines that are still within polygons.
            # Append each part as a separate line for accurate GDB lengths.
            for edge_part in full_polyline.intersect(poly_geom, 2):
                line_geoms.append(arcpy.Polyline(edge_part))
        else:
            # Otherwise, append the new line as-is.
            line_geoms.append(full_polyline)

    # Export intermediate geometries for testing review.
    for geoms, fc_name in [(test_multiparts, "MULTIS"), (test_extensions, "EXTENSIONS")]:
        arcpy.management.CopyFeatures(geoms, fc_name)
    stopwatch.stamptime(msg=f"{guid} POLYLINES CREATED")

    # Sort by length; option to retain only the max length lines, discard the rest.
    line_geoms_by_length = sorted(line_geoms, key=lambda x: x.length, reverse=True)
    stopwatch.stamptime(msg=f"{guid} TRANSECTS SORTED BY LENGTH")
    if discard_nonmax_transects:
        line_geoms_by_length = line_geoms_by_length[:1]

    # Write lines for this polygon to the feature class. Create UUIDs; mark the longest.
    flds = ["SHAPE@", "POLY_GUID", "LINE_GUID", "LONGEST"]
    with arcpy.da.InsertCursor(trans_fc, flds) as icurs:
        for i, line_geom in enumerate(line_geoms_by_length):
            if i == 0:
                icurs.insertRow([line_geom, guid, uuid.uuid4(), "X"])
            else:
                icurs.insertRow([line_geom, guid, uuid.uuid4(), None])

    stopwatch.stamptime(msg=f"WROTE {guid} TRANSECTS\n")

# Remove records where the geometry is identical.
# This should only happen when an edge is extended through a polygon, and ends
#   up being perfectly coincident with an internal line.
before_lines = int(arcpy.management.GetCount(transects)[0])
arcpy.management.DeleteIdentical(in_dataset=transects, fields="Shape")
after_lines = int(arcpy.management.GetCount(transects)[0])

stopwatch.stamptime(msg=f"{before_lines - after_lines} IDENTICAL LINE(S) REMOVED")
stopwatch.stamptime(msg="PROCESS COMPLETE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 21:57:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1269237#M26771</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2023-04-14T21:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278757#M26822</link>
      <description>&lt;P&gt;I've put together a model that generates an approximation of the longest line contained within a polygon. It's quite similar to&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215483"&gt;@VinceE&lt;/a&gt;&amp;nbsp;'s solution but done through modelbuilder.&lt;/P&gt;&lt;P&gt;It iterates through a feature class and goes through each polygon with a unique ID and then generates points along the boundaries of the polygon at a specified distance, generates a table with all possible combinations of points and the distance between each pair, it then deletes the duplicates that are created as you end up with a row for a to b and one for b to a for each combination of points, from these points it generates lines between each pair, it then clips all the lines to the original polygon and selects the one with the maximum length.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Longest line model" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68031iBF51557F1EF2EF78/image-size/large?v=v2&amp;amp;px=999" role="button" title="RobertEisler_7-1681477606272.png" alt="Longest line model" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Longest line model&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;See step by step below for how to set up the different parameters in the model.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Iterate Feature Selection (Optional)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Using this means the model will run through the same process for each polygon within a feature class that has a unique ID from the field you have selected. The model can also&amp;nbsp; be run with just a feature class as input but it will ignore individual polygons within the feature class and will generate a single longest line from the whole feature. E.g I have been using this to find the longest line across each island in a cluster of islands. If using the iterator it will generate a line for each island, if just using feature class which has multiple islands stored in it I will end up with a single line across the longest island.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_8-1681478042505.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68032iC10E5246B8BE1D6A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_8-1681478042505.png" alt="RobertEisler_8-1681478042505.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Generate points&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Input feature is your polygon of interest. Set distance at which points should be placed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_1-1681477355155.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68023i53B6305CB8A99F30/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_1-1681477355155.png" alt="RobertEisler_1-1681477355155.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Generate near&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Input features and Near features are the same layer, the points that were generated in the previous step. Search radius should be large enough to encompass your whole polygon.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_2-1681477373468.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68024i4B9B85CFB7CA236E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_2-1681477373468.png" alt="RobertEisler_2-1681477373468.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Delete Identical&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Input is the table generated in the previous step.&lt;/P&gt;&lt;P&gt;Deletes half the records as each combination of points is calculated in the near table in one direction and then the other e.g. Y to X is one row and X to Y is a new row which is identical but in the opposite direction.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_3-1681477391451.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68025i0E1862AD5F85AEFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_3-1681477391451.png" alt="RobertEisler_3-1681477391451.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;XY to line&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Input is the table with duplicates removed from the previous step. Make sure to set spatial reference to the same as your map.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_4-1681477407684.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68026iE18807A327D477EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_4-1681477407684.png" alt="RobertEisler_4-1681477407684.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pairwise clip&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Clips lines generated in previous step to the original polygon. Input features is lines from previous step, Clip features is the polygon you started with.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_5-1681477421911.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68027i28B9DDCA351B6927/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_5-1681477421911.png" alt="RobertEisler_5-1681477421911.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Select&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This selects the longest line from the set of lines you have generated and outputs as a feature class. The expression below has the format Field&amp;nbsp; = (SELECT MAX(Field) FROM (Table)).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertEisler_6-1681477443725.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68028i53F972E1DB392018/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertEisler_6-1681477443725.png" alt="RobertEisler_6-1681477443725.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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 13:24:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278757#M26822</guid>
      <dc:creator>RobertEisler</dc:creator>
      <dc:date>2023-04-14T13:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278861#M26823</link>
      <description>&lt;P&gt;Curious about this approach--any chance you would be able to attach a copy of your toolbox here?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 16:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278861#M26823</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2023-04-14T16:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278923#M26824</link>
      <description>&lt;P&gt;Yeah no problem.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 19:37:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278923#M26824</guid>
      <dc:creator>RobertEisler</dc:creator>
      <dc:date>2023-04-14T19:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Longest Line Within a Polygon</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278956#M26825</link>
      <description>&lt;P&gt;Thanks for sharing! None of the below is criticism, just observations; I think both of our approaches are good for different scenarios, and your version has shown me some errors and improvements in my own version.&lt;/P&gt;&lt;P&gt;I like your approach because it may be more applicable than mine for some real-world situations. My computer would catch fire (or just take forever) if I tried to use my code to process a real-world island polygon because there would likely be hundreds of thousands (more?) of vertex pairs, a problem that you solve by "generalizing" with "Generate Points Along Line." So, I will implement this change in my own tool based on a total vertex count or something like that.&lt;/P&gt;&lt;P&gt;Reviewing your approach has also shown me that while I still stand behind my edge transect approach, my internal line approach is INCORRECT. So, thanks for offering a different perspective.&lt;/P&gt;&lt;P&gt;My longest line (measurements all in US Feet) is shown in &lt;STRONG&gt;&lt;FONT color="#000000"&gt;Black&lt;/FONT&gt;&lt;/STRONG&gt;, yours is in &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Red&lt;/STRONG&gt;&lt;/FONT&gt;, and my (I am now realizing) incorrect "entirely internal" line is shown in &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Blue&lt;/STRONG&gt;&lt;/FONT&gt;. So, disregard Blue, I need to remove that feature.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_0-1681507257472.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68074i5F52BD270481AB05/image-size/large?v=v2&amp;amp;px=999" role="button" title="VinceE_0-1681507257472.png" alt="VinceE_0-1681507257472.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;For absolute accuracy, I think my two-vertex algorithm is the best approach, but for realistic use on complex polygons (islands, parcels, etc.) your approach could likely get pretty darn close, and probably requires far less processing time. Another exampl--again, mine in &lt;STRONG&gt;Black&lt;/STRONG&gt;, yours in &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Red&lt;/STRONG&gt;&lt;/FONT&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_2-1681507550872.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68076iAA8D01EA47B3857C/image-size/large?v=v2&amp;amp;px=999" role="button" title="VinceE_2-1681507550872.png" alt="VinceE_2-1681507550872.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing to watch out for with your toolbox would be holes in polygons, as well as concave polygons. As you can see, your line is "longer" here, but passes through a hole. The second image shows your line going out of bounds in a concave polygon.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_1-1681507488217.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68075i8693B176A4181187/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VinceE_1-1681507488217.png" alt="VinceE_1-1681507488217.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_3-1681508012512.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68077i7ECC2445B5CB899E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VinceE_3-1681508012512.png" alt="VinceE_3-1681508012512.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the alternate approach, very helpful in thinking about this problem further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 21:36:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/longest-line-within-a-polygon/m-p/1278956#M26825</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2023-04-14T21:36:47Z</dc:date>
    </item>
  </channel>
</rss>

