Original User: luke.kaimI am very new to python and the syntax. I am trying to write code so that It takes a shapefile with any amounts of rows and break that file into individual shapefiles with 1,000,000 records each. Then with the outputs I need to do a number of steps. I am much better at understanding the big picture then I am at coding it.
import arcpy, sys, os, re,glob
from arcpy import env
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:\\Users\\Luke Kaim\\Documents\\university_of_maine\\research4\\test2"
rasterpoints_shp = "rasterpoints.shp"
fieldName= "FID"
recordsCounted = 0
number=0
featureClass = "rasterpoints_shp"
i=0
files=""
nextFile = str(outfile[i+1])+".shp"
rows = arcpy.SearchCursor(featureClass)
for row in rows:
number += row.getValue(fieldName)
if recordsCounted ==1000000:
arcpy.CreateFeature(nextFile,"")
recordsCounted =0
i=i+1
recordsCounted += 1
row = rows.next()
for files in glob.glob("outfile" "+" "*"):
# Process: Select
arcpy.Select_analysis(rasterpoints_shp, point0_shp, "\"FID\" >=0 AND \"FID\" <100000")
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(point0_shp, Output_Layer, "", "", "Shape Shape VISIBLE NONE;FID FID VISIBLE NONE;POINTID POINTID VISIBLE NONE;GRID_CODE GRID_CODE VISIBLE NONE")
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(Output_Layer, "COMPLETELY_WITHIN", APPROACH_POLYGON_Project_shp, "", "NEW_SELECTION")
# Process: Select Layer By Location (2)
arcpy.SelectLayerByLocation_management(point0_Layer, "COMPLETELY_WITHIN", "", "", "SWITCH_SELECTION")
# Process: Feature To Point
arcpy.FeatureToPoint_management(point0__5_, FinalPoint0_shp, "CENTROID")
# Process: Add XY Coordinates
arcpy.AddXY_management(ProjectFinalPoint0_shp)
fc = "outfile"
prj = r"C:\\Program Files\\ArcGIS\\Desktop10.0\\Coordinate Systems\\Geographic Coordinate Systems\\World\\WGS 1984.prj"
spatRef = arcpy.SpatialReference(prj)
env.geographicTransformations = "NAD_1983_To_WGS_1984_1"
rows = arcpy.UpdateCursor(fc, "", spatRef)
for row in rows:
geom = row.shape
row.POINT_X = geom.centroid.X
row.POINT_Y = geom.centroid.Y
rows.updateRow(row)
del row, rows
# Process: Merge (2)
arcpy.Merge_management("'ProjectFinalPoint0.shp'", File1_shp, "POINTID \"POINTID\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,POINTID,-1,-1;GRID_CODE \"GRID_CODE\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,GRID_CODE,-1,-1;ORIG_FID \"ORIG_FID\" true true false 0 Long 0 0 ,First,#,ProjectFinalPoint0.shp,ORIG_FID,-1,-1;POINT_X \"POINT_X\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,POINT_X,-1,-1;POINT_Y \"POINT_Y\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,POINT_Y,-1,-1;POINT_Z \"POINT_Z\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,POINT_Z,-1,-1;POINT_M \"POINT_M\" true true false 0 Double 0 0 ,First,#,ProjectFinalPoint0.shp,POINT_M,-1,-1")
print"Finished"