1

I am trying to create a separate skyline shapefile for every feature ID I have in my point file by splitting them into multiple files. The code works fine, except splitting them into multiple shapefiles takes extremely long time. I have 65000 points in the shapefile. I have attached a photo of how I split my files. Once I split them, I point to each shapefile using the below code.

Splitting so many points currently takes about 25-30 hours on my computer. I use QGIS for this because I do not have advanced license for arcpy.Split_analysis tool to work with ArcMap.

Is there a better way than splitting the point file every time?

import arcpy, glob
# reading all the shapefiles
arcpy.env.workspace = "C:\\centrelinepoints"
files = glob.glob("C:\\centrelinepoints\*.shp")      


#running the skyline function on each point file separately.

for file in files:

    ## creating a unique name extension for each skyline shape output file based on its feature ID.    
    name = file                
    parts = name.split('_')      
    newname = parts[5]
    final = newname.split('.')
    FID = final[0]


    ## definiing the output layer location and name based on their feature ID.
    output_layer = "H:\\skylineshapes\Skyline_" + FID + ".shp"
    output_angle = "H:\\skylineangles\Skyline_" + FID + ".dbf"

    arcpy.Skyline_3d(file, output_layer, inSurface)

    arcpy.SkylineGraph_3d(file, output_layer, "0", "ADDITIONAL_FIELDS", output_angle)

Splitting Method Image

1 Answer 1

3

Not guaranteeing that this is the best, but it made 1000 single point shapefiles in 171 seconds, which would still be just over 3 hours for 65000, but better than 25 hours!

import arcpy
fc = r'C:\junk\split\thousand_points.shp'
count = 0
with arcpy.da.SearchCursor(fc,'*') as cursor:
    for row in cursor:
        arcpy.CreateFeatureclass_management(r'C:\junk\split','shp_' + str(count),'POINT',fc)
        iCur = arcpy.da.InsertCursor(r'C:\junk\split\shp_' + str(count) + '.shp',cursor.fields)
        iCur.insertRow(row)
        del iCur
        print (count)
        count += 1
3
  • When I try to open the file on ArcMap, it gives an error: 050013: Error decoding feature layer Commented Dec 15, 2016 at 0:32
  • That may be a separate question. The above works for me.
    – phloem
    Commented Dec 15, 2016 at 0:35
  • Thanks, the problem was the spatial reference. Once I specified, it worked completely fine :) Commented Dec 15, 2016 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.