def buildSubArray( fc, extent, dist_x, dist_y ): # Determine the number of points that can fit in the x and y directions # in the extent of the polygon, and create a centered grid in this extent. # Note: points are equidistant in the chosen coordinate system (and NOT # on ground, unless you are working with an equidistant - hence rather # local - coordinate system). range_x = extent.xmax-extent.xmin nPoints_x = (int) (range_x / dist_x) start_x = extent.xmin + 0.5 * (range_x - nPoints_x * dist_x) range_y = extent.ymax-extent.ymin nPoints_y = (int) (range_y / dist_y) start_y = extent.ymin + 0.5 * (range_y - nPoints_y * dist_y) point = gp.CreateObject( 'POINT' ) cursor = gp.InsertCursor( fc ) for i_y in range( nPoints_y ) : for i_x in range( nPoints_x ) : feature = cursor.NewRow() point.x = start_x + i_x * dist_x point.y = start_y + i_y * dist_y feature.shape = point cursor.InsertRow( feature ) del feature del cursor del point print '--- Start.\n' # -- Initialization. # Create and initialize the Geoprocessor. import arcgisscripting gp = arcgisscripting.create( 9.3 ) gp.SetProduct( 'ArcInfo' ) gp.Workspace = r'C:\Users\wannaz\Documents\Projects\ArcGIS General\CreateArrayOfPoints\project.gdb' gp.OverwriteOutput = 1 # Define setup-specific parameters. polygon_fc = 'polygons' temporary_fc = '__points' clipped_fc_base = 'clippedPoints_' xSpacing = 5 ySpacing = xSpacing # Create a layer from the polygon feature class for select() purpose. polygon_layer = 'polygons_layer' gp.MakeFeatureLayer_management( polygon_fc, polygon_layer ) # Extract the OBJECTID field name. polygon_desc = gp.Describe( polygon_layer ) polygon_OIDFieldName = polygon_desc.OIDFieldName # -- Loop over polygons. rows = gp.SearchCursor( polygon_layer ) row = rows.Next() while row : oid = row.GetValue( polygon_OIDFieldName ) print ' Processing polygon', oid, '..', # - Create array of points that covers the extent of current polygon. gp.CreateFeatureclass( gp.Workspace, temporary_fc, "POINT", polygon_fc, "", "", polygon_desc.SpatialReference ) extent = row.shape.Extent buildSubArray( temporary_fc, extent, xSpacing, ySpacing ) # - Select current polygon and clip. whereClause = polygon_OIDFieldName + " = " + str( oid ) gp.SelectLayerByAttribute_management( polygon_layer, "NEW_SELECTION", whereClause ) clipped_fc = clipped_fc_base + str( oid ) gp.Clip_analysis( temporary_fc, polygon_layer, clipped_fc ) print "done." row = rows.Next() del rows del row # -- Union? # If you were interested in the union of sub grids but not in the sub grids # themselves, you could create them in_memory to be faster. In such case, you # could create a list of sub grid names in the loop above, that you would pass # to the Union_analysis() tool/method. You would have to delete the temporary # sub grids afterwards. # PS: it would take about two minutes for me to update this script for it to # perform the union, so let me know if it would help. # -- Mr. Proper. gp.Delete_management( temporary_fc ) gp.Delete_management( polygon_layer ) print '\n--- End of Job.'
This is a pretty old post, but if you're still around I wouldn't mind seeing the union code. I was able to implement your code with some tweaks