I have to generate thousands of cells as a grid, and then I have to assign values to the cells, so far I know the a fishnet tool can generate the grid but how can I manage to create the offset. May some one have better Idea.
The details of the grid are as illustrated in the attached diagram.
I have 5 Rows and 6 column, after the 3rd column the grid should start with B, other numbering should be the same as A.
Solved! Go to Solution.
I guess you could use something like this:
def main():
import arcpy
# settings
fc_out = r'C:\GeoNet\RectangleBlocks\data.gdb\result01'
sr = arcpy.SpatialReference(2276) # NAD_1983_StatePlane_Texas_North_Central_FIPS_4202_Feet?
x_start = 2523853.5 # lower left
y_start = 7124354.1 # lower left
rect_width = 10.0
rect_height = 5.0
num_blocks_h = 6
num_blocks_v = 5
num_rect_in_block_h = 4
num_rect_in_block_v = 8
spacing_h = 3.0
spacing_v = 3.0
rectangles = []
# loop through blocks
for block_h in range(num_blocks_h):
for block_v in range(num_blocks_v):
# loop through rectangles
for rect_h in range(num_rect_in_block_h):
for rect_v in range(num_rect_in_block_v):
x_min = x_start + block_h * spacing_h + block_h * num_rect_in_block_h * rect_width + rect_h * rect_width
y_min = y_start + block_v * spacing_v + block_v * num_rect_in_block_v * rect_height + rect_v * rect_height
x_max = x_min + rect_width
y_max = y_min + rect_height
rectangle = CreateRactangle(x_min, y_min, x_max, y_max, sr)
rectangles.append(rectangle)
arcpy.CopyFeatures_management(rectangles, fc_out)
def CreateRactangle(x_min, y_min, x_max, y_max, sr):
coords = [[x_min, y_min], [x_min, y_max], [x_max, y_max],
[x_max, y_min], [x_min, y_min]]
return arcpy.Polygon(arcpy.Array([arcpy.Point(*coord) for coord in coords]), sr)
if __name__ == '__main__':
main()
Which results in:
The Only problem I am facing now, is how to generate the grid with offset.
I mean did fishnet support creating the polygons with offset, for each row and column?
You can use the fishnet as you commented for each block of 32 rectangles, but if you have many blocks you might want to script it using some python code. For that you would need to define the initial coordinate (lower left for instance), the number of blocks horizontally and vertically, the size of each rectangle (width and height) and the spacing between the blocks.
thanks , yes I do have many blocks, I have to think of that script.
If you can provide the following data:
... I'm sure we can help you with that script
Thank you Bakker for your help.
the initial coordinate (lower left for instance)= (2523853.5,7124354.1)
The spatial reference to be used (NAD83 / Texas North Central(ftUS) )
the number of blocks horizontally and vertically, (Horizontally 6, Vertically 5
the size of each rectangle (width and height): 40x40ft
the spacing between the blocks: 3ft
after that I need to divide each block to 32 sub sections (w:10ft h:5ft) just like what I have in attached pic, and fill the attribute similar as shown in the attached pic.
I guess you could use something like this:
def main():
import arcpy
# settings
fc_out = r'C:\GeoNet\RectangleBlocks\data.gdb\result01'
sr = arcpy.SpatialReference(2276) # NAD_1983_StatePlane_Texas_North_Central_FIPS_4202_Feet?
x_start = 2523853.5 # lower left
y_start = 7124354.1 # lower left
rect_width = 10.0
rect_height = 5.0
num_blocks_h = 6
num_blocks_v = 5
num_rect_in_block_h = 4
num_rect_in_block_v = 8
spacing_h = 3.0
spacing_v = 3.0
rectangles = []
# loop through blocks
for block_h in range(num_blocks_h):
for block_v in range(num_blocks_v):
# loop through rectangles
for rect_h in range(num_rect_in_block_h):
for rect_v in range(num_rect_in_block_v):
x_min = x_start + block_h * spacing_h + block_h * num_rect_in_block_h * rect_width + rect_h * rect_width
y_min = y_start + block_v * spacing_v + block_v * num_rect_in_block_v * rect_height + rect_v * rect_height
x_max = x_min + rect_width
y_max = y_min + rect_height
rectangle = CreateRactangle(x_min, y_min, x_max, y_max, sr)
rectangles.append(rectangle)
arcpy.CopyFeatures_management(rectangles, fc_out)
def CreateRactangle(x_min, y_min, x_max, y_max, sr):
coords = [[x_min, y_min], [x_min, y_max], [x_max, y_max],
[x_max, y_min], [x_min, y_min]]
return arcpy.Polygon(arcpy.Array([arcpy.Point(*coord) for coord in coords]), sr)
if __name__ == '__main__':
main()
Which results in:
Yes Yes that's it. Thank you Bakker, I did not test it yet but from code and the result, hat was exactly what I am looking for. its just missing the attribute tables, I will try the field calculator for that.
Will get back to you ASAP.
I do appreciate that
Thank you Xander, this worked as supposed to be "smarter".
One last question-is it possible to generate the attribute as requested earlier?.
Thanks Again
With the attribute table you are referring to labels for each rectangle shown in you image, right?
If so, let's clear up some doubts I have about the coding. Please correct me where I'm wrong.
Are these assumptions correct?