Introduction to querying data

You can perform a SQL or spatial query to access a subset of the data in a . The results of the query can contain the , , or both attributes and geometry, for each matching record. These results can be used for further processing or can be displayed in an application.

How to query a feature service

To perform SQL and spatial queries, you reference the main Esri Leaflet plugin. The L.esri.Query operation can be used to query feature, map, and image services.

  1. Reference the Esri Leaflet plugin.
  2. Find the URL of the service against which you want to query.
  3. Set the service URL and the feature layer ID.
  4. Define the SQL or spatial query.

Example

Query a feature layer (spatial)

In this example, you perform a spatial query to find which parcels intersect a geometry. Available spatial queries include: within, contains, intersects, and overlaps.

1
2
3
4
5
6
7
8
9
10
11
<script src="https://unpkg.com/esri-leaflet@3.0.14/dist/esri-leaflet.js"
    integrity="sha512-oUArlxr7VpoY7f/dd3ZdUL7FGOvS79nXVVQhxlg6ij4Fhdc4QID43LUFRs7abwHNJ0EYWijiN5LP2ZRR2PY4hQ=="
    crossorigin=""></script>
<script>
 parcels
    .query()
    .intersects(feature.geometry)
    .ids(function (error, queryResult) {
      parcels.setWhere("OBJECTID IN (" + queryResult.join(",") + ")");
    });
</script>

Tutorials

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close