alex_bn_lee

导航

[1005] Convert a Shapely polygon to an Esri polygon using ArcPy

To convert a Shapely polygon to an Esri polygon using ArcPy, you can follow these steps:

  1. Create a Shapely Polygon:

    • First, create your desired Shapely polygon using the Shapely library in Python.
  2. Convert to Esri Polygon:

    • Use the arcpy.FromWKB() function to convert the Shapely polygon’s WKB (Well-Known Binary) representation to an Esri polygon.
    • Example:
      from shapely.geometry import Polygon
      import arcpy
      
      # Create a Shapely polygon
      shapely_polygon = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
      
      # Convert to Esri polygon
      esri_polygon = arcpy.FromWKB(shapely_polygon.wkb)
      
      # Now you can use 'esri_polygon' in your ArcPy workflows
  3. Write to a Feature Class:

    • You can write the Esri polygon to a new feature class using an insert cursor.
    • Example:
      new_fc = r"C:\path\to\your\geodatabase.gdb\NewFeatureClass"
      with arcpy.da.InsertCursor(new_fc, ["SHAPE@"]) as cursor:
          cursor.insertRow([esri_polygon])

Remember to adjust the code according to your specific Shapely polygon and desired feature class. Let me know if you need further assistance! 😊 1

 
 

posted on 2024-06-11 11:34  McDelfino  阅读(5)  评论(0编辑  收藏  举报