<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Point.within(layer) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492636#M38618</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thx alot, its work very well!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did work on the code to be able to filter some result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lyr_path = r'X:\Polygone.lyr'&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; coords = (Var_x1, Var_y1)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; epsg = 4326&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lyr_file = arcpy.mp.LayerFile(lyr_path)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; lyr = lyr_file.listLayers()[0]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; point = arcpy.PointGeometry(arcpy.Point(*coords), arcpy.SpatialReference(epsg))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.SelectLayerByLocation_management(&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; lyr,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; "CONTAINS",&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; point,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; selection_type="NEW_SELECTION"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; )&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; arcpy.SelectLayerByAttribute_management(lyr, selection_type="REMOVE_FROM_SELECTION", where_clause="Croquis1 IS NULL")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at this point " print(arcpy.GetCount_management(lyr)) " will give me a count of 3.&lt;/P&gt;&lt;P&gt;but when i try :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; with arcpy.da.SearchCursor(lyr, 'Ticket_Number') as cursor:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(row)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it print the information of the&amp;nbsp;&lt;STRONG&gt;r'X:\Polygone.lyr&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What can i do to only print the 3 answers of&amp;nbsp;&lt;STRONG&gt;print(arcpy.GetCount_management(lyr))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thx alot &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Nov 2018 20:40:22 GMT</pubDate>
    <dc:creator>Jean-SimonLevert</dc:creator>
    <dc:date>2018-11-29T20:40:22Z</dc:date>
    <item>
      <title>Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492634#M38616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sr = arcpy.SpatialReference(4326)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Laye = arcpy.mp.LayerFile(r'X:\Polygone.lyr')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lyr = Laye.listLayers("*")[0]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; point = arcpy.PointGeometry(arcpy.Point(Var_x1, Var_y1), sr)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; print(point.within(lyr))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm doing something wrong.&lt;/P&gt;&lt;P&gt;I'm trying to get a &lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;Boolean awser if True or False point is in a .lyr file&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;Does anyone see what's wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;Thx alot &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:36:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492634#M38616</guid>
      <dc:creator>Jean-SimonLevert</dc:creator>
      <dc:date>2018-11-28T17:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492635#M38617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ArcPy Geometry methods don't operate on sets of geometries, like most geoprocessing tools, the methods operate on individual geometries.&amp;nbsp; This means you cannot pass &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;arcpy.Point.within&lt;/SPAN&gt; a data set either directly or through a feature layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A LYR file doesn't contain any data, it contains references to data, so a point can never be "in a .lyr file."&amp;nbsp; That said, I do understand what you are attempting to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recommend using Select Layer By Location because it operates on data sets through feature layers and also accepts ArcPy Geometry objects for selecting geometries.&amp;nbsp; I want to test something before suggesting specific code, will get back to you a bit later.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;:&amp;nbsp; This is the overall approach I would go with&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

lyr_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to layer file&lt;/SPAN&gt;
coords &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# tuple containing x,y coordinates&lt;/SPAN&gt;
epsg &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# epsg code for coordinate system&lt;/SPAN&gt;

lyr_file &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LayerFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr_path&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lyr_file&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
point &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PointGeometry&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;coords&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SpatialReference&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;epsg&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;"CONTAINS"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; point&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; selection_type&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NEW_SELECTION"&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetCount_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:40:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492635#M38617</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T21:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492636#M38618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thx alot, its work very well!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did work on the code to be able to filter some result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lyr_path = r'X:\Polygone.lyr'&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; coords = (Var_x1, Var_y1)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; epsg = 4326&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lyr_file = arcpy.mp.LayerFile(lyr_path)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; lyr = lyr_file.listLayers()[0]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; point = arcpy.PointGeometry(arcpy.Point(*coords), arcpy.SpatialReference(epsg))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.SelectLayerByLocation_management(&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; lyr,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; "CONTAINS",&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; point,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; selection_type="NEW_SELECTION"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; )&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; arcpy.SelectLayerByAttribute_management(lyr, selection_type="REMOVE_FROM_SELECTION", where_clause="Croquis1 IS NULL")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at this point " print(arcpy.GetCount_management(lyr)) " will give me a count of 3.&lt;/P&gt;&lt;P&gt;but when i try :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; with arcpy.da.SearchCursor(lyr, 'Ticket_Number') as cursor:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(row)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it print the information of the&amp;nbsp;&lt;STRONG&gt;r'X:\Polygone.lyr&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What can i do to only print the 3 answers of&amp;nbsp;&lt;STRONG&gt;print(arcpy.GetCount_management(lyr))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thx alot &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2018 20:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492636#M38618</guid>
      <dc:creator>Jean-SimonLevert</dc:creator>
      <dc:date>2018-11-29T20:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492637#M38619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Odd, ArcPy DA cursor should honor the selection set.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple questions since I don't have access to the data.&amp;nbsp; First, how many records are in the data source referenced in the layer file?&amp;nbsp; Second, where are you making the initial selection so you can then remove items from the selection?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2018 03:10:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492637#M38619</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-11-30T03:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492638#M38620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is more then 400 000 polygons. I want to see if there is a polygon at a x,y. Then with SelectLayerByLocation_managenent the result is 9 with Getcount_management. But I have to remove those with "croquis1 IS NULL" so Getcount_management return 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why if Getcount_management(lyr) = 3&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: #ffffff; border: 0px; font-weight: bold;"&gt;with arcpy.da.SearchCursor(lyr, 'Ticket_Number') as cursor:&lt;/STRONG&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;STRONG style="background-color: #ffffff; border: 0px; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&lt;/STRONG&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;STRONG style="background-color: #ffffff; border: 0px; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(row)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Will print 400 000+ 'Ticket_Number'?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Thx alot☺️&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2018 11:51:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492638#M38620</guid>
      <dc:creator>Jean-SimonLevert</dc:creator>
      <dc:date>2018-11-30T11:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Point.within(layer)</title>
      <link>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492639#M38621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see what you are talking about, and have run across this same kind of issue with a surprising number of ArcPy functions in Pro.&amp;nbsp; Specifically, the code runs as expected within ArcGIS Pro itself, e.g,. in the interactive Python window, but it does not run as expected outside of Pro.&amp;nbsp; Just for kicks, try running the code in Pro itself?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the 4th bug like this I have seen in the past 2 weeks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2018 18:50:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-within-layer/m-p/492639#M38621</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-11-30T18:50:35Z</dc:date>
    </item>
  </channel>
</rss>

