Introduction to querying data

You can perform a SQL or spatial query to access a subset of the data in a feature service. The results of the query can contain the attributes, geometry, 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.

Use dark colors for code blocksCopy
           
1
2
3
4
5
6
7
8
9
10
11
<script src="https://unpkg.com/esri-leaflet@3.0.8/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>

Learn more in the Query a feature layer (SQL) and Query a feature layer (spatial) tutorials. If you want to learn about querying related records using the L.esri.Related.Query, go to the API reference.

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