Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import arcpy
  2. arcpy.env.workspace = "path\to\workspace\MaintenanceDivisions"
  3. arcpy.env.overwriteOutput=True
  4. #variables
  5. md = "MaintenanceDivisions.shp"
  6. out = arcpy.CreateUniqueName( "clipped.shp" )
  7. mfp = "dissolved.shp"
  8. try:
  9. #clip polygons from selected area
  10. rows = arcpy.SearchCursor(md)
  11. row = rows.next()
  12. for row in rows:
  13. feat = row.Shape
  14. arcpy.Clip_analysis([mfpd], feat, out, "")
  15. row = rows.next()
  16. except arcpy.ExecuteError as e:
  17. print(e)
  18. del rows
  19.  
  20. import arcpy, os
  21.  
  22. outws = r'C:temp'
  23. poly_single = r'C:temppoly_single.shp' # The polygon to be clipped
  24. poly_multi = r'C:temppoly_multi.shp' # The clip features
  25.  
  26. rows = arcpy.SearchCursor(poly_multi)
  27.  
  28. count = 0 # Start a counter to name output polygons
  29. for row in rows: # Loop through individual features of "poly_multi"
  30. out_poly = os.path.join(outws, "out_poly" + str(count)) # Assemble the output poly name and path
  31. arcpy.Clip_analysis(poly_single, row.Shape, out_poly)
  32. count = count + 1
  33.  
  34. # Clean up...Not necessary using "with" statement used in arcpy.da module
  35. del row
  36. del rows
  37.  
  38. import arcpy
  39.  
  40. p1 = "C:/p1.shp" #Multiple polygons
  41. p2 = "C:/p2.shp" #Single polygon
  42.  
  43. with arcpy.da.SearchCursor(p1, ("FID", "SHAPE@")) as p1_cur:
  44. with arcpy.da.SearchCursor(p2, "SHAPE@") as p2_cur:
  45. for r2 in p2_cur:
  46. for r1 in p1_cur:
  47. intersect = r2[0].intersect(r1[1], 4)
  48. arcpy.CopyFeatures_management(intersect, "C:/{0}.shp".format(r1[0]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement