Filter for polygon

193
9
07-13-2020 11:13 PM
BraulioCordova
New Contributor III

I am wanting to do a point filter for a polygon. But when passing the geometry, the points do not filter. Allen Thompson

 mapView.whenLayerView(areaspriorizadas).then(function(featureLayerView) {
       featureLayerView.filter = {
            geometry: distrito,
            patialRelationship: "contains"
        };    
      });
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Are the points and the polygon in the same spatial reference?

0 Kudos
BraulioCordova
New Contributor III

If they are in the same coordinate system. But when I pass the parameter of the polygon geometry. I get an error.

let areaspriorizadas = new FeatureLayer({
        url:
        urlservices+"/Areas_Priorizadas/FeatureServer/0",      
        
        //definitionExpression: "id_dist="+ubigeo,
       // mapView.extent = featureLayer.fullExtent;
        outFields: ["trimestre"]
        //featureReduction: distrito
       // renderer: distrito       
      });
      map.add(areaspriorizadas);    
      //****************************** */
      mapView.whenLayerView(areaspriorizadas).then(function(featureLayerView) {
       featureLayerView.filter = {
            //where: "trimestre='I Trimestre'",         
           geometry: distrito.event.geometry//Problems in geometry when passing the polygon stops to the exclusion of points.
            patialRelationship: "contains"
        };    
      });
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

I don't see in your code what distrito.event object is.

0 Kudos
BraulioCordova
New Contributor III

areaspriorizadas is type point
distrito is type polygon
Filtering points within a polygon is required

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

The issue is that if 

geometry: distrito.event.geometry

was a single polygon with the same spatial reference as areaspriorizadas then there would not be any issue.

So are you sure that distrito.event.geometry is not null and is a single polygon geometry?

0 Kudos
BraulioCordova
New Contributor III

What happens is that I want to filter the points (areaspriorizadas) within a polygon (distrito). At the time of passing the extension to consider. It does not filter the contained points. I have seen that if I put (geometry: view.extent) it filters the extension of the map. But I don't know how to filter the points inside the polygon (distrito)

 var distrito = new FeatureLayer({
        url: urlservices+"/Demarcacion_Territorial/MapServer/2",
        title: 'Distrito',
        //*** ADD ***//
        definitionExpression: "id_dist="+ubigeo,
        //*** ADD ***//
        popupTemplate: {  // Enable a popup
          title: "Distrito"// Show attribute value
         "content": "<b>Departamento:</b> {departamento}<br><b>Provincia:</b> {provincia}<br><b>Distrito:</b> {distrito}<br>"
          }
        });
        map.add(distrito);
 // Visualizacion de areas priorizadas
       let areaspriorizadas = new FeatureLayer({
        url:
        urlservices+"/Areas_Priorizadas/FeatureServer/0",  
        //definitionExpression: "id_dist="+ubigeo,
       // mapView.extent = featureLayer.fullExtent;
        outFields: ["trimestre"]
        //featureReduction: distrito
       // renderer: distrito       
      });
      map.add(areaspriorizadas);    
      distrito.queryExtent().then(function(response){mapView.goTo(response.extent);})
      
      //****************************** */
      mapView.whenLayerView(areaspriorizadas).then(function(featureLayerView) {
       featureLayerView.filter = {
            //where: "trimestre='I Trimestre'",
            geometry: mapView.geometry.Extent(distrito),
            patialRelationship: "contains"
        };    
      });
 
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

As I mentioned before you can only filter the view on a Single geometry. So you would have to get a single feature from the distro featurelayer and grab the one features geometry to use in the filter.

      mapView.whenLayerView(areaspriorizadas).then(function(featureLayerView) {
var polyFeat, query;
query = distrito.createQuery();
query.outSpatialReference = view.spatialReference;
query.returnGeometry = true;
distrito.queryFeatures(query).then(function(results){
polyFeat = results.features[0].geometry;
});
featureLayerView.filter = {
geometry: polyFeat,
patialRelationship: "contains"
};
});
BraulioCordova
New Contributor III

I have tried the code, but it still does not filter the points by polygon. Maybe there is something I am not considering.

mapView.whenLayerView(featureLayer).then(function(featureLayerView) {
        var polyFeatquery;
        query = distrito.createQuery();
        //query.where = "id_dist='"+ubigeo+"'";          
        query.outSpatialReference = mapView.spatialReference;
        query.returnGeometry = true;
        distrito.queryFeatures(query).then(function(results){
          polyFeat = results.features[0].geometry;
        });
        featureLayerView.filter = {
           geometry: polyFeat,
           spatialRelationship: "contains"
         };    
       });
0 Kudos
BraulioCordova
New Contributor III
I made some adjustments and it worked perfectly. Thank you very much for your support
 mapView.whenLayerView(featureLayer).then(function(featureLayerView) {        
        var query = distrito.createQuery();
        query.outSpatialReference = mapView.spatialReference;
        query.returnGeometry = true;
        distrito.queryFeatures(query).then(function(results){
          featureLayerView.filter = {
            geometry: results.features[0].geometry,
            patialRelationship: "contains"
          }; 
        });           
       });
0 Kudos