Filter by geometry

3741
4
Jump to solution
10-14-2014 09:12 AM
Labels (1)
ReneRubalcava
Frequent Contributor

So the API has a where option and a setWhere method with other time filter methods.

L.esri.Layers.FeatureLayer | Esri Leaflet

Is there a way to set the geometry as well? Right now it uses the bounds of the map to limit queries, but can I override that pretty easily somewhere?

Right now I can jump through some hoops using Turf to do point-in-polygon searches, but it doesn't work if I need to check points outside the bounds of the map not queried yet.

Turfjs/turf-inside · GitHub

 

I'm thinking I could just query the data on my own, convert to GeoJSON and use Turf + properties filtering to search my results, but was kind of hoping there was a workflow in Esri-Leaflet already to do this. Any ideas?

 

Thanks.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
PatrickArlt1
Esri Contributor

Also forgot you could also use L.esri.get to query the endpoint directly and let the server do the spatial query for you.

L.esri.get(featureLayerQueryUrl, {

  spatialRel: "esriSpatialRelIntersects",

  geometryType: "esriGeometryPoint",

  geometry: L.esri.Utils.geojsonToArcGIS(geojsonPoint)

}, function(error, response){

    var geojson = L.esri.Utils.responseToFeatureCollection(response);

});

This is dropping down pretty low into the request and utilities methods. But you will save yourself from using Turf and they are all documented in the API ref API Reference | Esri Leaflet

View solution in original post

0 Kudos
4 Replies
PaulCrickard1
Occasional Contributor II

If you are doing it yourself, try the REST API - it will return JSON and allows you to select a geometry and a geometry type. Your URL should be

http://YourArcServerDomainName/ArcGIS/rest/services/yourFeatureName/FeatureServer/0/query

Hit that with a formatted AJAX request and get back the JSON rep of the results

Looks like the ESRI-Leaflet plugin only runs where on the whole data set. My money is on it just hitting your rest endpoint anyway so do it yourself.

0 Kudos
PatrickArlt1
Esri Contributor

I get where you are coming from Rene.

You were probably hoping for something like this

L.esri.featureLayer(featureLayer, {

  spatialMethod: 'intersects',

  geometry: latlng

}).addTo(map);

Implementing this would be VERY difficult since the assumption that features are only loaded inside the current viewport is baked into Esri Leaflet all the way down to the core.

That said this did remind me of a feature I wanted to add Add additional spatial query types to L.esri.Tasks.Query · Issue #374 · Esri/esri-leaflet · GitHub.

Once this is implemented you could do something like the following to render all polygons that intersect a point.

L.esri.Tasks.query(featureLayer).intersects(latlng).run(function(error, geojson){

  // use L.GeoJSON to add features to map

});

For right now you can just use the raw L.esri.Tasks.query to query as many features as possible and use Turf on the client side for your point in polygon.

// queries all features up to the transfer limit (usually 1000-2000)

L.esri.Tasks.query(featureLayer).run(function(error, geojson){

  // now use Turf over all the geojson

});

PatrickArlt1
Esri Contributor

Also forgot you could also use L.esri.get to query the endpoint directly and let the server do the spatial query for you.

L.esri.get(featureLayerQueryUrl, {

  spatialRel: "esriSpatialRelIntersects",

  geometryType: "esriGeometryPoint",

  geometry: L.esri.Utils.geojsonToArcGIS(geojsonPoint)

}, function(error, response){

    var geojson = L.esri.Utils.responseToFeatureCollection(response);

});

This is dropping down pretty low into the request and utilities methods. But you will save yourself from using Turf and they are all documented in the API ref API Reference | Esri Leaflet

0 Kudos
ReneRubalcava
Frequent Contributor

Thanks Patrick!

I think this will work, because ultimately what I end up doing is an attribute and spatial query of the data.

I keep forgetting about L.esri.get, ha.

0 Kudos