Like I have a rectangle (3x5m) as a vector layer... now I would like to fill this 3x5m rectangle optimal with smaller polygons in a given shape (1x2m rectangles).I didn't find anything helpful yet....
Another suggestion is to:
1. Start editing in ArcMap the feature class with 3x5 polygons,
2. Select (all) the 3x5 polygons,
3. Go to Editor, then Buffer...
4. Enter -1 (negative one) to make an inner polygon 1x3
Scott
Here's my attempt. It's not necessarily the optimal. You could rotate the grid axes and compare to see which holds the most rectangles. There is also the distinct possibility that neither orientations optimally fill the original rectangle (i.e. there is often a remainder that could fit more small rectangles rotated by 90 degrees).
recs <SPAN class="operator token">=</SPAN> <SPAN class="string token">'recs'</SPAN> <SPAN class="comment token"># rectangle feature layer</SPAN> mbr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MinimumBoundingGeometry_management<SPAN class="punctuation token">(</SPAN>recs<SPAN class="punctuation token">,</SPAN>r<SPAN class="string token">'in_memory\mbr'</SPAN><SPAN class="punctuation token">,</SPAN>mbg_fields_option<SPAN class="operator token">=</SPAN><SPAN class="string token">'MBG_FIELDS'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># get MBRs</SPAN> grids <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># merge list to be populated</SPAN> out_grid <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'in_memory\out_grid'</SPAN> <SPAN class="comment token"># final output</SPAN> sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>recs<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>spatialReference <SPAN class="comment token"># CRS</SPAN> grid_h <SPAN class="operator token">=</SPAN> <SPAN class="number token">20</SPAN> <SPAN class="comment token"># cell height, aligned to long axis of rectangle</SPAN> grid_w <SPAN class="operator token">=</SPAN> <SPAN class="number token">10</SPAN> <SPAN class="comment token"># cell width, aligned to short axis of rectangle</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>mbr<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'OID@'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'MBG_Width'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'MBG_Length'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'MBG_Orientation'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> spatial_reference<SPAN class="operator token">=</SPAN>sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># loop through MBRs</SPAN> grid <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'in_memory\grid_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># temp grid</SPAN> dy <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>cos<SPAN class="punctuation token">(</SPAN>math<SPAN class="punctuation token">.</SPAN>radians<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># y diff along long side</SPAN> dx <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>sin<SPAN class="punctuation token">(</SPAN>math<SPAN class="punctuation token">.</SPAN>radians<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># x diff along long side</SPAN> y_axis <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">+</SPAN> dx<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">' '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">+</SPAN> dy<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># rotation point</SPAN> origin <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">' '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># starting point</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>outputCoordinateSystem <SPAN class="operator token">=</SPAN> sr <SPAN class="comment token"># set CRS for fishnet</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateFishnet_management<SPAN class="punctuation token">(</SPAN>grid<SPAN class="punctuation token">,</SPAN>origin<SPAN class="punctuation token">,</SPAN>y_axis<SPAN class="punctuation token">,</SPAN>grid_w<SPAN class="punctuation token">,</SPAN>grid_h<SPAN class="punctuation token">,</SPAN>int<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">/</SPAN>grid_h<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>int<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">/</SPAN>grid_w<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>labels<SPAN class="operator token">=</SPAN><SPAN class="string token">'NO_LABELS'</SPAN><SPAN class="punctuation token">,</SPAN>geometry_type<SPAN class="operator token">=</SPAN><SPAN class="string token">'POLYGON'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># make fishnet</SPAN> temp_lyr <SPAN class="operator token">=</SPAN> <SPAN class="string token">'sel_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># temp layer</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>grid<SPAN class="punctuation token">,</SPAN>temp_lyr<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># make feature layer</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByLocation_management<SPAN class="punctuation token">(</SPAN>temp_lyr<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"WITHIN_CLEMENTINI"</SPAN><SPAN class="punctuation token">,</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>selection_type<SPAN class="operator token">=</SPAN><SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># select grid cells inside MBR</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>temp_lyr<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"SWITCH_SELECTION"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># switch selection</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>DeleteFeatures_management<SPAN class="punctuation token">(</SPAN>temp_lyr<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># delete cells outside MBR</SPAN> grids<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>grid<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># add to merge list</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Merge_management<SPAN class="punctuation token">(</SPAN>grids<SPAN class="punctuation token">,</SPAN>out_grid<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># merge</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hi, see if this gets you close:
http://arcgis.com/home/item.html?id=9398bd2232cb4c8490b0b05015364d28
you still should be able to use rotation...
Thank you Robert, I tryed to do it with the gridindexfeature. Works kind of, except (as you said) for the North-South arrangement...and the arrangement is very important So far it is the best solution but I still not what I try to find...I'll try to find out how to get the generated gridindex into the right arrangement.... What i further have is the aspect of the "to be filled polygons"..so maybe I can integrate this aspect into the gridindex ?!...
Still thankful for your helpAnd if I find out something I'll let you know here
The best I can think is to run Grid Index Feature tool. On your polygons. You can specify exactly a 1 x 2 meter polygon. However they will be aligned north south etc.
Then use the Select by location tool to select all grids that intersect the boundary and delete them.
about hundreds and they are in every kind of shape
How many polygons are you talking about? and are they all 3 x 5?
@ Danthe problem is, the "package" is given and fix There will be a given vector layer with the "lager polygons" needed to be filled....
I would like to place "the maximum nr" of 1x2 polygon in this space, not completely fill the polygon... means, in this example it should not place more polygons cause as you said, this would be an exceed of the boundary..
It is far easier to create the bounds and orientation at the smaller scale, then aggregate them to the larger unit, than to ensure that everything fits within those bounds. Sort of like squeezing stuff into a package... it is easier to wrap what exists than to put something into a pre-existing container.
Do you only want one 1 x 2 polygon in the 3 x 5?
If you want to completely fill the polygon you would need to change the size of your 1 x 2's as the result would not be the same area, either a 1 x 2 would be cut down or exceed the boundary. You could stack 1 x 2's 3 high but would either need to go 4 or 6 wide
If you only want to create a single 1 x 2 in the middle of the 3 x 5 that's an easy fix.
Andreas,
I am unaware of any tool that will meet your needs then.
Create your own.... I have blogged some ideas and code several times...
here is one link
Dear AdrianThanks too for the answer, as you can see down below, the "minimum bounding rectangle" does not what I'm looking for.. (or am I wrong ? )
Thank you Robert for the quick answer
interesting approach, I already tried it out but the problem is, I have more than one Polygon to fill, and they are not lined up straight...
There is a tool called "create fishnet" in the Data Mangement Tools > Feature Class > Create Fishnet
You can specify the Template Extent as your 3m x 5m rectangle and then set the Cell Size Widget to 1m and Cell Size height to 2m and leave Number or Rows and Columns black. This will create a new FC with cells that are 1m by 2m.
Try the Minimum Bounding Polygon tool:
Creating a minimum bounding rectangle—Help | ArcGIS for Desktop
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.