<?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 Re: Creating line segments in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516403#M71222</link>
    <description>&lt;P&gt;I have, I get the follow. The top and bottom row are offset for some reason. It could be because not a symmetrical square.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2024 22:17:06 GMT</pubDate>
    <dc:creator>CCWeedcontrol</dc:creator>
    <dc:date>2024-08-07T22:17:06Z</dc:date>
    <item>
      <title>Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515665#M71212</link>
      <description>&lt;P&gt;I have this polygon that I need to cut into pieces, 10 horizontal and 10 vertical blocks. My though was converting the polygon to polylines, (pic 1) then break the polyline into 4 parts,&amp;nbsp; then creating the 10 horizontal and 10 vertical lines, then converting those into polygons. The issue I am having is that when creating the segments, the west and south boundary have 20 segments.&lt;/P&gt;&lt;P&gt;Not know why 20 segments were being created for the west and south boundary. I did a arcpy.management.FeatureVerticesToPoints and that it was creating two segments for the west and south polylines (pic 2).&lt;/P&gt;&lt;P&gt;I am not sure how this can happen given that the polyline comes from the polygon.&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="c"&gt;import arcpy

# Define your workspace and input feature class
arcpy.env.workspace = r"C:\Temp\Sec.gdb"
input_fc = "Sec_1N2W30"
output_fc = "Polygons_Output"  # This will store the polygons
segment_fc = "Segmented_Polylines"  # This will store the segmented polylines

# Convert features to polygons
arcpy.management.FeatureToPolygon(input_fc, output_fc)

# Create an empty Polyline feature class for segmented polylines
arcpy.CreateFeatureclass_management(arcpy.env.workspace, segment_fc, "POLYLINE")

# Create a cursor to insert segmented polylines
with arcpy.da.InsertCursor(segment_fc, ["SHAPE@"]) as insert_cursor:
    # Iterate over each polygon in the output_fc
    with arcpy.da.SearchCursor(output_fc, ["SHAPE@"]) as search_cursor:
        for row in search_cursor:
            polygon = row[0]
            
            # Get the exterior ring of the polygon
            exterior_ring = polygon.boundary()

            # Iterate over each part of the exterior ring
            for part in exterior_ring:
                if len(part) &amp;lt; 2:
                    continue
                for i in range(len(part) - 1):
                    p1 = part[i]
                    p2 = part[i + 1]
                    line = arcpy.Polyline(arcpy.Array([p1, p2]))
                    length = line.length
                    segment_length = length / 10

                    # Create points at each segment interval
                    points = [p1]
                    for j in range(1, 10):  # 9 additional points to create 10 segments
                        segment_point = line.positionAlongLine(j * segment_length)
                        points.append(segment_point.firstPoint)
                    points.append(p2)

                    # Ensure no duplicate points by slightly adjusting them
                    unique_points = []
                    for point in points:
                        if not unique_points or unique_points[-1] != point:
                            unique_points.append(point)

                    # Create polylines from the unique points and insert them
                    for k in range(len(unique_points) - 1):
                        segment_line = arcpy.Polyline(arcpy.Array([unique_points[k], unique_points[k + 1]]))
                        insert_cursor.insertRow([segment_line])

print("Segmented polylines created successfully in", segment_fc)&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;</description>
      <pubDate>Tue, 06 Aug 2024 18:16:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515665#M71212</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2024-08-06T18:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515739#M71213</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/49959"&gt;@CCWeedcontrol&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/cartography/grid-index-features.htm" target="_blank" rel="noopener"&gt;Grid Index Feature Tool&lt;/A&gt; to automatically create a grid over any feature. If this isn't what you are looking for then you might try the Fishnet tool.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 20:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515739#M71213</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-08-06T20:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515820#M71215</link>
      <description>&lt;P&gt;I did try that and create fishnet, but every time I run those the grid doesn't stay within the polygon. It seems to be rotated and not aligned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the attached picture, the tan is the original polygon and the red grid is what is created by the Grid Index Features tool, it doesn't follow the original polygon.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 21:21:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1515820#M71215</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2024-08-06T21:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516219#M71221</link>
      <description>&lt;P&gt;Have you tried this option?&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/subdivide-polygon.htm" target="_blank"&gt;Subdivide Polygon (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 17:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516219#M71221</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-08-07T17:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516403#M71222</link>
      <description>&lt;P&gt;I have, I get the follow. The top and bottom row are offset for some reason. It could be because not a symmetrical square.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 22:17:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516403#M71222</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2024-08-07T22:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516647#M71225</link>
      <description>&lt;P&gt;That is what your issue is. If you are looking for a perfected grid, then the grid to index is your best option. Otherwise, the subdivide polygon is the only tool that would get your polygon to divide as proportionately as possible.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 13:27:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516647#M71225</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-08-08T13:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating line segments</title>
      <link>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516991#M71229</link>
      <description>&lt;P&gt;Ya, the Grid to index is not going to work.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 21:47:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-line-segments/m-p/1516991#M71229</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-08-08T21:47:39Z</dc:date>
    </item>
  </channel>
</rss>

