<?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 FeatureLayer.query() with a Spatial Filter Issue in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1475907#M10044</link>
    <description>&lt;P&gt;I am trying to use the GIS library to extract parcel data for my City from our County's data. I'm using a spatial filter, but for some reason I am not getting all the data returned. There are random holes in my data. We are interested in about 15% of the records, so I'd rather not have to extract all the data to get what we need.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcgis.gis import GIS
from arcgis.geometry import Geometry
from arcgis.features import FeatureLayer
from arcgis.geometry import filters
import pandas as pd

# Define the geometry
geometry = Geometry({
    "rings": [
        [
            [-121.261, 44.2128],
            [-121.2618, 44.3237],
            [-121.0991, 44.3257],
            [-121.1004, 44.212]
        ]
    ],
    "spatialReference": {"wkid": 4326}
})

# Connect to the GIS
gis = GIS()

# URL of the Feature Layer
url = 'https://[service url]/FeatureServer/0'

feature_layer = FeatureLayer(url)

query_result = feature_layer.query(geometry_filter=filters.intersects(geometry), out_fields='*', return_geometry=True)

# Convert the query result to a DataFrame
df = query_result.sdf

# Save the DataFrame to a CSV file
output_csv = r'C:\Users\dummy\Desktop\output.csv'
df.to_csv(output_csv, index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-20 160926.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/104691i18D51A7E0286ABCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-20 160926.png" alt="Screenshot 2024-05-20 160926.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2024 23:12:45 GMT</pubDate>
    <dc:creator>LRoberts_RDM</dc:creator>
    <dc:date>2024-05-20T23:12:45Z</dc:date>
    <item>
      <title>FeatureLayer.query() with a Spatial Filter Issue</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1475907#M10044</link>
      <description>&lt;P&gt;I am trying to use the GIS library to extract parcel data for my City from our County's data. I'm using a spatial filter, but for some reason I am not getting all the data returned. There are random holes in my data. We are interested in about 15% of the records, so I'd rather not have to extract all the data to get what we need.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcgis.gis import GIS
from arcgis.geometry import Geometry
from arcgis.features import FeatureLayer
from arcgis.geometry import filters
import pandas as pd

# Define the geometry
geometry = Geometry({
    "rings": [
        [
            [-121.261, 44.2128],
            [-121.2618, 44.3237],
            [-121.0991, 44.3257],
            [-121.1004, 44.212]
        ]
    ],
    "spatialReference": {"wkid": 4326}
})

# Connect to the GIS
gis = GIS()

# URL of the Feature Layer
url = 'https://[service url]/FeatureServer/0'

feature_layer = FeatureLayer(url)

query_result = feature_layer.query(geometry_filter=filters.intersects(geometry), out_fields='*', return_geometry=True)

# Convert the query result to a DataFrame
df = query_result.sdf

# Save the DataFrame to a CSV file
output_csv = r'C:\Users\dummy\Desktop\output.csv'
df.to_csv(output_csv, index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-20 160926.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/104691i18D51A7E0286ABCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-20 160926.png" alt="Screenshot 2024-05-20 160926.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 23:12:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1475907#M10044</guid>
      <dc:creator>LRoberts_RDM</dc:creator>
      <dc:date>2024-05-20T23:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer.query() with a Spatial Filter Issue</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1476475#M10050</link>
      <description>&lt;P&gt;My guess is you are hitting the max record limit as I don't see logic to page through results. The good news is that getting all records should be relatively simple now. In more recent versions of the API, the query method has a "return_all_records" param you can set to True and the method will automatically keep calling the service until all records that satisfy the where clause are found.&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 18:49:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1476475#M10050</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-05-21T18:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer.query() with a Spatial Filter Issue</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1524128#M10445</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86309"&gt;@EarlMedina&lt;/a&gt;&amp;nbsp;Thanks for the reply. I tried adding that parameter into my query, but it didn't seem to help. The service I'm querying is a little funk in that it seems to be built with a join between a layer and a table, and I'm wondering if that's hosing it somehow.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 23:44:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-query-with-a-spatial-filter-issue/m-p/1524128#M10445</guid>
      <dc:creator>LRoberts_RDM</dc:creator>
      <dc:date>2024-08-19T23:44:15Z</dc:date>
    </item>
  </channel>
</rss>

