Select to view content in your preferred language

Feature layer query

7283
21
Jump to solution
01-06-2016 08:03 PM
deleted-user-x7XmeRtVHyGE
Deactivated User

Hello all,

I'm looking for some strategic advice and sample code if possible.

I'm working with a few very large feature services. We are serving these out to a web-based app. Layer1 is a polygon layer and Layer2 is a line layer, with those lines falling within the polygons in Layer1.

Right now our application passes an ID to Layer1 that we then use Layer1.setDefinitionExpression() to segment the data. Now we need to take that boundary and use it to query and display the data from Layer2 where it is within the subset of Layer1.

Any advice on how to proceed? Feature services are necessary for both because of the need for editing.

Enjoy the day,

Mike

0 Kudos
21 Replies
RobertScheitlin__GISP
MVP Emeritus
deleted-user-x7XmeRtVHyGE
Deactivated User

Hi Robert,

Thanks for all your help. Below is the query that works. You are correct the spatialReference needed to be changed. I also needed to add in the EntityID field to query into Query2.

Thank you. I got at least 2 beers for you at the UC this year!

Enjoy the day,

Mike

function queryGo(){
var geoms = [];
var union;
//console.log(union);
var query = new Query();
query.where = entityIDexp;
query.outfields = ["*"];
query.returnGeometry = true;
query.spatialReference = sr;
query.outSpatialReference = sr;
geoms.SpatialReference = sr;
//union.SpatialReference = sr;
featureLayer.queryFeatures(query, function(featureSet){   
    for (var i = 0; i < featureSet.features.length; i++) {   
    var feature = featureSet.features;   
    geoms.push(feature.geometry);
    console.log(geoms);
    }
    union = geometryEngine.union(geoms);
    console.log(union.toJson());
   
    var query2 = new Query();   
    query2.geometry = union.geometry;
    query2.where = entityIDexp;
    console.log(union);
    query2.returnGeometry = true;
    query2.spatialReference = sr;
    query2.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;   
    pondLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW);
    pondLayer.queryCount(query2, function(count) {
    console.log(count + " features satisfied the input query")});
    pondLayer.getSelectedFeatures();
    pondLayer.refresh();
    console.log('refreshed')
});

            function queryGo(){
            var geoms = [];
            var union;
            //console.log(union);
            var query = new Query();
            query.where = entityIDexp;
            query.outfields = ["*"];
            query.returnGeometry = true;
            query.spatialReference = sr;
            query.outSpatialReference = sr;
            geoms.SpatialReference = sr;
            //union.SpatialReference = sr;
            featureLayer.queryFeatures(query, function(featureSet){   
                for (var i = 0; i < featureSet.features.length; i++) {   
                var feature = featureSet.features;   
                geoms.push(feature.geometry);
                console.log(geoms);
                }
                union = geometryEngine.union(geoms);
                console.log(union.toJson());
               
                var query2 = new Query();   
                query2.geometry = union.geometry;
                query2.where = entityIDexp;
                console.log(union);
                query2.returnGeometry = true;
                query2.spatialReference = sr;
                query2.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;   
                pondLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW);
                pondLayer.queryCount(query2, function(count) {
                console.log(count + " features satisfied the input query")});
                pondLayer.getSelectedFeatures();
                pondLayer.refresh();
                console.log('refreshed')
             });

0 Kudos