Guest User

Untitled

a guest
Feb 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. import arcpy
  2.  
  3. inFC = r"C:temptestLines.shp"
  4. outFC = r"C:temptestLinesSplit.shp"
  5.  
  6. if arcpy.Exists(outFC):
  7. arcpy.Delete_management(outFC)
  8. arcpy.CreateFeatureclass_management("C:/temp","testLinesSplit.shp","POLYLINE","#","DISABLED","DISABLED",inFC)
  9. arcpy.AddField_management(outFC,"inFID","LONG","#","#","#","#","NULLABLE","NON_REQUIRED","#")
  10.  
  11. iCursor = arcpy.da.InsertCursor(outFC, ["inFID","SHAPE@"])
  12.  
  13. with arcpy.da.SearchCursor(inFC,["OID@", "SHAPE@"]) as sCursor:
  14. for row in sCursor:
  15. inFID = row[0]
  16. # Print the current multipoint's ID
  17. #
  18. print("Feature {0}:".format(row[0]))
  19. partnum = 0
  20.  
  21. # Step through each part of the feature
  22. #
  23. for part in row[1]:
  24. # Print the part number
  25. #
  26. print("Part {0}:".format(partnum))
  27.  
  28. # Step through each vertex in the feature
  29. #
  30. prevX = None
  31. prevY = None
  32. for pnt in part:
  33. if pnt:
  34. # Print x,y coordinates of current point
  35. #
  36. print("{0}, {1}".format(pnt.X, pnt.Y))
  37. if prevX:
  38. array = arcpy.Array([arcpy.Point(prevX, prevY),
  39. arcpy.Point(pnt.X, pnt.Y)])
  40. polyline = arcpy.Polyline(array)
  41. iCursor.insertRow([inFID,polyline])
  42. prevX = pnt.X
  43. prevY = pnt.Y
  44. else:
  45. # If pnt is None, this represents an interior ring
  46. #
  47. print("Interior Ring:")
  48. partnum += 1
  49.  
  50. del iCursor
  51.  
  52. arcpy.JoinField_management(outFC,"inFID",inFC,"FID","#")
  53.  
  54. import arcpy
  55. import numpy as np
  56.  
  57. InFcVF = r"input.shp" # input feature class
  58. OutFcVF = r"output.shp" # output feature class
  59.  
  60.  
  61. print "Daten gelesen.."
  62.  
  63. # Creates NumPy array from Input Feature
  64.  
  65. array = arcpy.da.FeatureClassToNumPyArray(InFcVF,["SHAPE@XY"], "", sr, explode_to_points=True)
  66.  
  67. print "Numpy Array created.."
  68.  
  69. # if Feature as Array wasnt created
  70.  
  71. if array.size == 0:
  72. arcpy.AddError(InFcVF + " contains no feature.")
  73.  
  74. # Multipoint Feature from arra
  75. else:
  76. print "Aus Numpy Array wurde ein neues Multipoint Feature (VF) erstellt.."
  77. arcpy.da.NumPyArrayToFeatureClass(array, OutFcVF, ['SHAPE@XY'], sr)
  78.  
  79.  
  80. print "Numpy Array created.."`
Add Comment
Please, Sign In to add comment