Introduction to querying data

A feature service is a type of data service that stores spatial data (features) and non-spatial data. It provides access to the data with feature layers and tables. You can use SQL queries, spatial queries, or a combination of both to get data from a feature service. The results can be used for further processing or 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.

Steps

  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 blocks
           
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.