<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help with python code in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219320#M716</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am very new to python and the syntax. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; number += row.getValue(fieldName)
if recordsCounted ==1000000:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeature(nextFile,"")
recordsCounted =0
i=i+1

recordsCounted += 1
row = rows.next()

for files in glob.glob("outfile" "+" "*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Process: Select
arcpy.Select_analysis(rasterpoints_shp, point0_shp, "\"FID\" &amp;gt;=0 AND \"FID\" &amp;lt;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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row.shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_X = geom.centroid.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_Y = geom.centroid.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; 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"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:41:48 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-11T10:41:48Z</dc:date>
    <item>
      <title>Help with python code</title>
      <link>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219320#M716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am very new to python and the syntax. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; number += row.getValue(fieldName)
if recordsCounted ==1000000:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeature(nextFile,"")
recordsCounted =0
i=i+1

recordsCounted += 1
row = rows.next()

for files in glob.glob("outfile" "+" "*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Process: Select
arcpy.Select_analysis(rasterpoints_shp, point0_shp, "\"FID\" &amp;gt;=0 AND \"FID\" &amp;lt;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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row.shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_X = geom.centroid.X
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_Y = geom.centroid.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp; 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"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:41:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219320#M716</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T10:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with python code</title>
      <link>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219321#M717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made some changes to the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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
nextFile = str(outfile[i+1])+".shp"

rows = arcpy.SearchCursor(featureClass)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; number += row.getValue(fieldName)
if recordsCounted ==1000000:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeature(nextFile,"")
recordsCounted =0
i=i+1

recordsCounted += 1
row = rows.next()

for files in glob.glob("outfile" "+" "*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Make Feature Layer
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(files, Output_Layer, "", "", "Shape Shape VISIBLE NONE;FID FID VISIBLE NONE;POINTID POINTID VISIBLE NONE;GRID_CODE GRID_CODE VISIBLE NONE")


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Select Layer By Location
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(files, "COMPLETELY_WITHIN", APPROACH_POLYGON_Project_shp, "", "NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Select Layer By Location (2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(files, "COMPLETELY_WITHIN", "", "", "SWITCH_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Feature To Point
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureToPoint_management(files, FinalPoint0_shp, "CENTROID")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Add XY Coordinates
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddXY_management(files)

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = "files"

&amp;nbsp;&amp;nbsp;&amp;nbsp; prj = r"C:\\Program Files\\ArcGIS\\Desktop10.0\\Coordinate Systems\\Geographic Coordinate Systems\\World\\WGS 1984.prj"
&amp;nbsp;&amp;nbsp;&amp;nbsp; spatRef = arcpy.SpatialReference(prj)
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.geographicTransformations = "NAD_1983_To_WGS_1984_1"

&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, "", spatRef)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row.shape
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_X = geom.centroid.X
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.POINT_Y = geom.centroid.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row, rows

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Merge (2)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management("'files'", 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"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:41:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219321#M717</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T10:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help with python code</title>
      <link>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219322#M718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Luke,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could do something similar to the code below.&amp;nbsp; You will just need to update it for a shapefile rather than a feature class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\temp\python\test.gdb"

fc = "Cities"

count = str(arcpy.GetCount_management(fc))

x = 0
y = 1000000
z = 1

while x &amp;lt; int(count):
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = "OBJECTID &amp;gt; " + str(x) + "AND OBJECTID &amp;lt;= " + str(y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(fc, "Cities_FL", where)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("Cities_FL", "Cities_" + str(z))
&amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1000000
&amp;nbsp;&amp;nbsp;&amp;nbsp; y += 1000000
&amp;nbsp;&amp;nbsp;&amp;nbsp; z += 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:41:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/help-with-python-code/m-p/219322#M718</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T10:41:54Z</dc:date>
    </item>
  </channel>
</rss>

