<?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: Intersect a grid with another shp to retrieve information - Python in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1139856#M6156</link>
    <description>&lt;P&gt;I don't know Geopandas, but if you have access to arcpy, you can do it like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;grid = "path:/to/grid.shp"
pipes = "path:/to/pipes.shp"
grid_id_field = "GridID"  # unique identifier of your grid features
pipe_length_field = "PipeLength"  # name of the new field

# intersect grid and pipes
intersection = arcpy.analysis.Intersect([grid, pipes], "memory/intersection")

# read intersection into a list
# [ (GridID, PipeShape) ]
intersection_list = [row for row in arcpy.da.SearchCursor(intersection, [grid_id_field, "SHAPE@"])]

# add the new field to the grid
arcpy.management.AddField(grid, pipe_length_field, "DOUBLE")

# loop through the grid and fill the new field
with arcpy.da.UpdateCursor(grid, [grid_id_field, pipe_length_field]) as cursor:
    for grid_id, pipe_length in cursor:
        # get all pipe shapes in this grid cell
        pipe_shapes = [d[1] for d in intersection_list if d[0] == grid_id]
        # get total length of those shapes
        pipe_length = sum([s.length for s in pipe_shapes])
        # update field values
        cursor.updateRow([grid_id, pipe_length])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Feb 2022 15:19:04 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-02-02T15:19:04Z</dc:date>
    <item>
      <title>Intersect a grid with another shp to retrieve information - Python</title>
      <link>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1139824#M6155</link>
      <description>&lt;P&gt;I am using Python and I have two Shapefiles. One is a grid with equal Polygons and the other one is a shapefile representing a water network. I would like to count the pipe length in each cell of this grid. I have tried an overlay method but it returns an empty dataframe whereas both shapefiles have the same CRS.&lt;/P&gt;&lt;PRE&gt;print("Maillage/canalisation intersection...")
gdf_intersection_maille_cana=gpd.overlay(gdf_maillage,gdf_cana_total,how='intersection')
print(gdf_intersection_maille_cana)
print("Maillage/canalisation intersection done ! ")&lt;/PRE&gt;&lt;P&gt;The second step would be to count the length in each grid but I don't really how to proceed. Once I have counted, the objective is to create a new column in my gdf_maillage with the pipe length in each cell&lt;A href="https://www.olansitr.com/" target="_self"&gt;&amp;nbsp;&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 10:22:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1139824#M6155</guid>
      <dc:creator>JabbarKhan</dc:creator>
      <dc:date>2022-02-17T10:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Intersect a grid with another shp to retrieve information - Python</title>
      <link>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1139856#M6156</link>
      <description>&lt;P&gt;I don't know Geopandas, but if you have access to arcpy, you can do it like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;grid = "path:/to/grid.shp"
pipes = "path:/to/pipes.shp"
grid_id_field = "GridID"  # unique identifier of your grid features
pipe_length_field = "PipeLength"  # name of the new field

# intersect grid and pipes
intersection = arcpy.analysis.Intersect([grid, pipes], "memory/intersection")

# read intersection into a list
# [ (GridID, PipeShape) ]
intersection_list = [row for row in arcpy.da.SearchCursor(intersection, [grid_id_field, "SHAPE@"])]

# add the new field to the grid
arcpy.management.AddField(grid, pipe_length_field, "DOUBLE")

# loop through the grid and fill the new field
with arcpy.da.UpdateCursor(grid, [grid_id_field, pipe_length_field]) as cursor:
    for grid_id, pipe_length in cursor:
        # get all pipe shapes in this grid cell
        pipe_shapes = [d[1] for d in intersection_list if d[0] == grid_id]
        # get total length of those shapes
        pipe_length = sum([s.length for s in pipe_shapes])
        # update field values
        cursor.updateRow([grid_id, pipe_length])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 15:19:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1139856#M6156</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-02-02T15:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Intersect a grid with another shp to retrieve information - Python</title>
      <link>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1500911#M7100</link>
      <description>&lt;P&gt;Sports have played a significant role in shaping me into a better developer by instilling crucial skills and attributes that are transferable to my professional life. Here are some ways sports have contributed to my development as a software developer:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Wed, 03 Jul 2024 12:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1500911#M7100</guid>
      <dc:creator>sophiamartin</dc:creator>
      <dc:date>2024-07-03T12:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Intersect a grid with another shp to retrieve information - Python</title>
      <link>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1500912#M7101</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;SVIs are vital for enabling Layer 3 routing on a switch, facilitating inter-VLAN communication without the need for an external router By following the above steps, you can configure SVIs on your switch, allowing different VLANs to communicate efficiently.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;A href="https://thoroughbredlabs.co.uk/" target="_blank"&gt;https://thoroughbredlabs.co.uk/&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Jul 2024 12:08:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/intersect-a-grid-with-another-shp-to-retrieve/m-p/1500912#M7101</guid>
      <dc:creator>sophiamartin</dc:creator>
      <dc:date>2024-07-03T12:08:43Z</dc:date>
    </item>
  </channel>
</rss>

