Branched to a new question from: How to use ArcPy Geometry MeasureOnLine
Hey do you know how you would invoke the 'within' method? Been struggling with that one.
It's on the Geometry site, but, alas no good sample 😕 Geometry—Help | ArcGIS for Desktop
For the ArcPy 'within' method, I'm having a hard time coming up with a scenario where the CLEMENTINI option returns a result different from the PROPER option.
For example: I have a line and a rectangle. The line starts at a vertex of the rectangle and dangles into the interior of the rectangle. The methods line.within(rectangle, 'CLEMENTINI') and line.within(rectangle, 'PROPER') both produce True.
I expect the 'PROPER' option to return False since the end of the line intersects a vertex of the rectangle. As Vince said, the boundary of a line includes its start and end points, and the boundary polygon is its actual boundary. The relationship between these two geometries intersects at a point, so I'd think the 'PROPER' relation paramater would produce a False. At least that's how I read it in the documentation...
Any ideas why these are both True? Let me know if this is worth a separate discussion/question elsewhere in GeoNet.
Hi bixb0012 , for some reason my help page defaulted to 10.3 (that happens sometimes) and I didn't notice the enhancement. Very useful information and indeed a great addition to have control over the relation. Thanks for sharing!
Hi Vince Angelo , you are absolutely right. Yesterday I read an old 9.3 document where the Clementini rules were explained and the results correspond perfectly to that. Thanks for the additional information.
Xander Bakker, the screenshot you include at the top of your reply is from ArcGIS 10.3. The reason I point that out is starting in ArcGIS 10.4.x (I can't remember if it was 10.4 or 10.4.1) Esri added a relation parameter to many of the geometry spatial methods, including within: Geometry—Help | ArcGIS Desktop (10.4)
within (second_geometry, {relation})ParameterExplanationData Typesecond_geometryA second geometry.Objectrelation The spatial relationship type.BOUNDARY — Relationship has no restrictions for interiors or boundaries.CLEMENTINI — Interiors of geometries must intersect. Specifying CLEMENTINI is equivalent to specifying None. This is the default.PROPER — Boundaries of geometries must not intersect.(The default value is None)String
within (second_geometry, {relation})
A second geometry.
The spatial relationship type.
(The default value is None)
Although I am glad the relations were finally added, the default arguments are different between the ArcPy Geometry classes and Select Layer by Location for certain spatial methods, including within. For the ArcPy Geometry classes, the default relation is CLEMENTINI whereas the default or unqualified within for the Select Layer by Location tool is BOUNDARY.
So a line on the border of a polygon is not with the polygon, but if I add a single point to the line that is inside the polygon the line suddenly is within the polygon
If you look at the Clementini* rules, this makes perfect sense. A geometry is composed of boundary and interior. The boundary of a line is the start and end points; the boundary of a polygon is its perimeter ring(s) (points don't have interior). So the "within" relationship tests for an intersection of the (line) figure with the (polygon) interior, and "line on boundary" does not intersect the polygon interior (empty set), so it's not "within".
Then there's "Completely Within" and "Contains", and "Contained", but I have a scrum, so I'm not going there...
- V
*Eliseo Clementini, Paolino Di Felice, and Peter van Oosterom, A Small Set of Formal Topological Relationships Suitable for End-User Interaction, Proceedings of the Third International Symposium on Advances in Spatial Databases, p.277-295, June 23-25, 1993
xander_bakker This is awesome! Thanks!
Is it also possible to use Feature classes as the base and secondary geometry? I.e. set a point FC as a variable and a polygon as another variable and call:
Pt = "C:\...\Cities"
Pg = "C:\...\Counties"
Pt.within(Pg)
I tried running this in the IDE interface, but got an error. Any ideas?
I added a little additional test:
<SPAN class="comment token"># polyline on border of polygon</SPAN> line_coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"test 1: polyline on border of polygon is within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># polyline that ends on polygon border</SPAN> line_coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"test 2: polyline that end on border of polygon is within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># polyline that combines line 1 (within is false) and line 2 (within is true)</SPAN> line_coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"test 3: polyline that combines line 1 (within is False) and line 2 (within is True) is within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<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>
which resulted in...
test 1: polyline on border of polygon is within polygon: False test 2: polyline that end on border of polygon is within polygon: True test 3: polyline that combines line 1 (within is false) and line 2 (within is true) is within polygon: True<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
So a line on the border of a polygon is not with the polygon, but if I add a single point to the line that is inside the polygon the line suddenly is within the polygon... interesting ...
Hi Andrew Valenski , as the help states you have a base geometry which is compared to a comparison geometry to see if the base geometry is "within" the comparison geometry:
boolean_result = base_geometry.within(comparison_geometry)
Some examples:
<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> <SPAN class="keyword token">import</SPAN> arcpy sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polygon 2 x 2 with LL corner at 0,0</SPAN> coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polygon <SPAN class="operator token">=</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><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"polygon area:"</SPAN><SPAN class="punctuation token">,</SPAN> polygon<SPAN class="punctuation token">.</SPAN>area <SPAN class="comment token"># create point inside polygon and test within</SPAN> point <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"point within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> point<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create point at border of polygon</SPAN> point <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"point at border within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> point<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polyline inside polygon</SPAN> line_coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"polyline within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polyline part of border of polygon</SPAN> line_coords <SPAN class="operator token">=</SPAN> coords<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"polyline on border within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polyline that is within polygon but ends on border of polygon</SPAN> line_coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> line_coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"polyline ending on border of polygon within polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polyline<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polygon inside larger polygon</SPAN> coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polygon2 <SPAN class="operator token">=</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><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"small polygon within larger polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polygon2<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polygon with a single point on border of larger polygon</SPAN> coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polygon2 <SPAN class="operator token">=</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><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"small polygon with a single point on border of larger polygon is within larger polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polygon2<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create polygon thar shares and edge with larger polygon</SPAN> coords <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> polygon2 <SPAN class="operator token">=</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><SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> a <SPAN class="keyword token">in</SPAN> coords<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"small polygon which shares edge of larger polygon is within larger polygon:"</SPAN><SPAN class="punctuation token">,</SPAN> polygon2<SPAN class="punctuation token">.</SPAN>within<SPAN class="punctuation token">(</SPAN>polygon<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>
The results are:
polygon area: 4.0 point within polygon: True point at border within polygon: False polyline within polygon: True polyline on border within polygon: False polyline ending on border of polygon within polygon: True small polygon within larger polygon: True small polygon with a single point on border of larger polygon is within larger polygon: True small polygon which shares edge of larger polygon is within larger polygon: True<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.