Ok, attached I have the point data and the rectangle as polygon. I want to draw vertical line from each point (from the top to the bottom) and keep the information written in the LN column. After I want to make single polygons (resulting from the underlying rectangle and the lines together) and also keep the LN information in the single polygons. So in the end it shoudl be 13 single polygons, I hope you understand what I mean.
Best,
Tim
Dropbox - GW1.zip
Branched from: https://community.esri.com/thread/176544
Hi Tim Gattinger , see below the code I created based on the information in the point shapefile:
<SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN> <SPAN class="comment token"># Name: create_rectangles.py</SPAN> <SPAN class="comment token"># Purpose:</SPAN> <SPAN class="comment token">#</SPAN> <SPAN class="comment token"># Author: Xander</SPAN> <SPAN class="comment token">#</SPAN> <SPAN class="comment token"># Created: 01-04-2017</SPAN> <SPAN class="comment token">#-------------------------------------------------------------------------------</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="comment token"># parameters</SPAN> fc_in <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\GW1\ref_kal_ln\ref_kal_ln.shp'</SPAN> fc_out <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\GW1\rectangles_v01.shp'</SPAN> where <SPAN class="operator token">=</SPAN> <SPAN class="string token">'"ID" <14'</SPAN> fld_x_max <SPAN class="operator token">=</SPAN> <SPAN class="string token">'X'</SPAN> fld_y_max <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Y'</SPAN> fld_width <SPAN class="operator token">=</SPAN> <SPAN class="string token">'width'</SPAN> fld_height <SPAN class="operator token">=</SPAN> <SPAN class="string token">'length'</SPAN> <SPAN class="comment token"># create output featureclass</SPAN> sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>fc_in<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>spatialReference CreateFeatureClassTemplate<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> fc_in<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POLYGON"</SPAN><SPAN class="punctuation token">,</SPAN> fc_in<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># nested insert and search cursor</SPAN> flds <SPAN class="operator token">=</SPAN> GetAllFieldsWithoutSystemFields<SPAN class="punctuation token">(</SPAN>fc_in<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs_out<SPAN class="punctuation token">:</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>fc_in<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">,</SPAN> where<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> curs<SPAN class="punctuation token">:</SPAN> x_max <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN>flds<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>fld_x_max<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> y_max <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN>flds<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>fld_y_max<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> width <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN>flds<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>fld_width<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> height <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN>flds<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>fld_height<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> polygon <SPAN class="operator token">=</SPAN> CreateRectangle<SPAN class="punctuation token">(</SPAN>x_max<SPAN class="punctuation token">,</SPAN> y_max<SPAN class="punctuation token">,</SPAN> width<SPAN class="punctuation token">,</SPAN> height<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> polygon <SPAN class="keyword token">is</SPAN> <SPAN class="operator token">not</SPAN> None<SPAN class="punctuation token">:</SPAN> lst_row <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN> lst_row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> polygon row_out <SPAN class="operator token">=</SPAN> tuple<SPAN class="punctuation token">(</SPAN>lst_row<SPAN class="punctuation token">)</SPAN> curs_out<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN>row_out<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">GetAllFieldsWithoutSystemFields</SPAN><SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>fld<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> fld <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN> fld_shape <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>shapeFieldName fld_oid <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>OIDFieldName <SPAN class="keyword token">for</SPAN> fld_name <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN>fld_shape<SPAN class="punctuation token">,</SPAN> fld_oid<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> fld_name <SPAN class="keyword token">in</SPAN> flds<SPAN class="punctuation token">:</SPAN> flds<SPAN class="punctuation token">.</SPAN>pop<SPAN class="punctuation token">(</SPAN>flds<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>fld_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> flds<SPAN class="punctuation token">.</SPAN>insert<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> flds <SPAN class="keyword token">def</SPAN> <SPAN class="token function">CreateFeatureClassTemplate</SPAN><SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">,</SPAN> fc_in<SPAN class="punctuation token">,</SPAN> geomtype<SPAN class="punctuation token">,</SPAN> template<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> ws_name<SPAN class="punctuation token">,</SPAN> fc_name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN>fc_out<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureclass_management<SPAN class="punctuation token">(</SPAN>ws_name<SPAN class="punctuation token">,</SPAN> fc_name<SPAN class="punctuation token">,</SPAN> geomtype<SPAN class="punctuation token">,</SPAN> template<SPAN class="punctuation token">,</SPAN> spatial_reference<SPAN class="operator token">=</SPAN>sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">CreateRectangle</SPAN><SPAN class="punctuation token">(</SPAN>x_max<SPAN class="punctuation token">,</SPAN> y_max<SPAN class="punctuation token">,</SPAN> width<SPAN class="punctuation token">,</SPAN> height<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> pnt1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>x_max <SPAN class="operator token">-</SPAN> width<SPAN class="punctuation token">,</SPAN> y_max <SPAN class="operator token">-</SPAN> height<SPAN class="punctuation token">)</SPAN> pnt2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>x_max <SPAN class="operator token">-</SPAN> width<SPAN class="punctuation token">,</SPAN> y_max<SPAN class="punctuation token">)</SPAN> pnt3 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>x_max<SPAN class="punctuation token">,</SPAN> y_max<SPAN class="punctuation token">)</SPAN> pnt4 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>x_max<SPAN class="punctuation token">,</SPAN> y_max <SPAN class="operator token">-</SPAN> height<SPAN class="punctuation token">)</SPAN> lst_pnts <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>pnt1<SPAN class="punctuation token">,</SPAN> pnt2<SPAN class="punctuation token">,</SPAN> pnt3<SPAN class="punctuation token">,</SPAN> pnt4<SPAN class="punctuation token">,</SPAN> pnt1<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">return</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polygon<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN>lst_pnts<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN> main<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</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></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><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></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The upper part of the shapefile looks like this:
The attribute table of the resulting shapefile (attributes are transferred):
I have attached the resulting shapefile for you to examine.
Sure, I will follow you.
Dear Xander,
may I send you a message? Afaik in this community it only works if you would follow me..
When I look at the data I see that you are using a format (point featureclass) that is different from the original format used in the thread Create a line from points using attributes
I understand that you want to create vertical lines and use these to cut a rectangle in smaller parts in order to generate the smaller rectangles and assign values from the attributes of the input points. This may not be as straight forward as you hope, since the input points do not hold details on which points should be used together to form the line (although this will probably be those with the same X-coordinates):
I would like to suggest another input format (if possible) to make this process a lot easier. You basically have a constant Y (min and max) and a Xmin. When you know the width of each rectangle and you start with Xmin and apply the width you will be able to form the rectangles with little effort and it will be easy to maintain the attributes (for instance field LN):
Could you elaborate a little on what the data represents and where it comes from and what you want to achieve (apart from the smaller rectangles)?
Kind regards, Xander
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.