Late is better than never....This code generates equadistant points that more than covers the extent out the 'containerFC'. Further code could be written to limit the points to those that are contained in the containerFC... either in the insert cursor using the .contains() geometry method, or at the very end, a SelectByLocation and then export to a new FC.I put in a 'useRandomShift' flag so that the points don't necessarily have to be tied to the containerFC's extent.#Chris Snyder, WADNR, 20120126
import arcpy, math, random
containerFC = r"C:\csny490\test.shp"
outputFC = r"C:\csny490\out.shp"
spacing = 100
useRandomShift = True
arcpy.env.overwriteOutput = True
dsc = arcpy.Describe(containerFC)
dscExtent = dsc.extent
xMin = dscExtent.xMin
yMin = dscExtent.yMin
xMax = dscExtent.xMax
yMax = dscExtent.yMax
randomXshift = random.uniform(0, spacing)
randomYshift = random.uniform(0, spacing)
yOffset = math.sqrt((spacing **2) - ((spacing / 2) **2))
pntDict = {}
i = 0
rowNumber = 1
xCoord = xMin - spacing
yCoord = yMin - spacing
while xCoord < xMax + spacing or yCoord < yMax + spacing:
i = i + 1
if xCoord > xMax + spacing:
rowNumber = rowNumber + 1
xCoord = xMin - spacing
if bool(rowNumber & 1) == False:
xCoord = xCoord + spacing / 2
yCoord = yCoord + yOffset
elif i == 1:
xCoord = xCoord
else:
xCoord = xCoord + spacing
if useRandomShift == True:
pntDict = (xCoord + randomXshift, yCoord + randomYshift)
else:
pntDict = (xCoord, yCoord)
arcpy.CreateFeatureclass_management(outputFC[:-len(outputFC.split("\\")[-1]) - 1], outputFC.split("\\")[-1], "POINT", "", "", "", dsc.spatialreference, "", "", "", "")
shapeFieldName = arcpy.Describe(outputFC).shapeFieldName
insertRows = arcpy.InsertCursor(outputFC)
for pnt in pntDict:
insertRow = insertRows.newRow()
pointObj = arcpy.CreateObject("Point")
pointObj.X = pntDict[pnt][0]
pointObj.Y = pntDict[pnt][1]
insertRow.setValue(shapeFieldName, pointObj)
insertRows.insertRow(insertRow)
del pointObj, insertRow, insertRows