QueryTask on point and line feature not resulting into featureset

989
8
03-06-2011 07:42 PM
SowmyaK
New Contributor
Dear All,

            Its a very urgent issue. I am not able get feature on querying on point and line feature. Featureset length will be 0.I am giving my code here.Please help me..


       function createToolbar(map) {
            // Create the ESRI drawing toolbar
            toolbar = new esri.toolbars.Draw(map);
            dojo.connect(toolbar, "onDrawEnd", runGeometryQuery);
        }

       var lyrind;
        function runGeometryQuery(geometry)
         {
           var query = new esri.tasks.Query();
            query.returnGeometry = true;
            if (typeof (geometry) == "object")
             {
                query.geometry = geometry;
             }
           lyrind= document.getElementById("hidLayerIndex").value;
            query.outFields = ["*"];
            var queryTask = new esri.tasks.QueryTask(servicename+lyrind);

            // Perform the query, and call the data linking routine with
            // the results once the query executes successfully.
            dojo.connect(queryTask, "onComplete", geometryQuery_Complete);
            queryTask.execute(query);
          
        }

         // The query is done, now we'll take the query results to do the data linking
         function geometryQuery_Complete(featureSet) {
         alert(featureSet.features.length);//Its showing length = 0
            if ((featureSet != null) && (featureSet.features.length > 0))
            {
                // If there is at least one result
                var resultSymbol;
                var feature = featureSet.features[0];
                if(lyrind=="0" ){
                  resultSymbol= new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,
   new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
   new dojo.Color([255,0,0]), 1),
   new dojo.Color([0,255,0,0.25]));
   alert('in0');
}
                else if(lyrind=="1" || lyrind=="8"){
                  resultSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
                                                                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255, .8]), 2),
                                                                new dojo.Color([100, 100, 255, 0.8]));
                                                                 alert('in1or8');
}
                else
                {
                  resultSymbol=new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255,0,0]), 3);
                   alert('inelse');
}
                // add the selection highlight
                feature.setSymbol(resultSymbol);

                // display the graphics for the selected feature
                map.graphics.add(feature);
        
             }
             var code,disp;
if(lyrind=="0" || lyrind=="1" ||lyrind=="3")
{
code="FEATURECD";
disp ="OBJECTID";
}
else if(lyrind=="8" )
{
code="FEATURECODE";
disp ="SURVEY_NO";
}
          var ddlVillage_ProjWiseBudget = document.getElementById("ddlVillage_ProjWiseBudget");
          var context = 'SurveyNoSelection';
          var argument = 'ControlType=SurveyNoSelection';
          argument += '&SURVEY_NO=' + featureSet.features[0].attributes[disp];
          argument += '&FEATURECODE=' + featureSet.features[0].attributes
;         

       eval(Planning_CallBack);
}
0 Kudos
8 Replies
HemingZhu
Occasional Contributor III
Dear All,

            Its a very urgent issue. I am not able get feature on querying on point and line feature. Featureset length will be 0.I am giving my code here.Please help me..


       function createToolbar(map) {
            // Create the ESRI drawing toolbar
            toolbar = new esri.toolbars.Draw(map);
            dojo.connect(toolbar, "onDrawEnd", runGeometryQuery);
        }

       var lyrind;
        function runGeometryQuery(geometry)
         {
           var query = new esri.tasks.Query();
            query.returnGeometry = true;
            if (typeof (geometry) == "object")
             {
                query.geometry = geometry;
             }
           lyrind= document.getElementById("hidLayerIndex").value;
            query.outFields = ["*"];
            var queryTask = new esri.tasks.QueryTask(servicename+lyrind);

            // Perform the query, and call the data linking routine with
            // the results once the query executes successfully.
            dojo.connect(queryTask, "onComplete", geometryQuery_Complete);
            queryTask.execute(query);
          
        }

         // The query is done, now we'll take the query results to do the data linking
         function geometryQuery_Complete(featureSet) {
         alert(featureSet.features.length);//Its showing length = 0
            if ((featureSet != null) && (featureSet.features.length > 0))
            {
                // If there is at least one result
                var resultSymbol;
                var feature = featureSet.features[0];
                if(lyrind=="0" ){
                  resultSymbol= new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,
   new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
   new dojo.Color([255,0,0]), 1),
   new dojo.Color([0,255,0,0.25]));
   alert('in0');
}
                else if(lyrind=="1" || lyrind=="8"){
                  resultSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
                                                                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255, .8]), 2),
                                                                new dojo.Color([100, 100, 255, 0.8]));
                                                                 alert('in1or8');
}
                else
                {
                  resultSymbol=new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255,0,0]), 3);
                   alert('inelse');
}
                // add the selection highlight
                feature.setSymbol(resultSymbol);

                // display the graphics for the selected feature
                map.graphics.add(feature);
        
             }
             var code,disp;
if(lyrind=="0" || lyrind=="1" ||lyrind=="3")
{
code="FEATURECD";
disp ="OBJECTID";
}
else if(lyrind=="8" )
{
code="FEATURECODE";
disp ="SURVEY_NO";
}
          var ddlVillage_ProjWiseBudget = document.getElementById("ddlVillage_ProjWiseBudget");
          var context = 'SurveyNoSelection';
          var argument = 'ControlType=SurveyNoSelection';
          argument += '&SURVEY_NO=' + featureSet.features[0].attributes[disp];
          argument += '&FEATURECODE=' + featureSet.features[0].attributes
;         
       eval(Planning_CallBack);
}


Theorically, typeof (geometry) should definitely return a string "object". However, typeof null produces 'object' instead of 'null'. That means, in your case, if geometry== null, your statement: if (typeof (geometry) == "object") will be true. So you end up assign query.geometry = null; My suggestion is to use geometry.type to varify instead of typeof or just get rid of if (typeof (geometry) == "object")....
0 Kudos
SowmyaK
New Contributor
Hi Hzhu,

  My problem is in posted code for only polygon feature featureset will be retrieved. For Line and point feature featureset will be always empty. How can i get those feature's objectID "onDrawEnd".

Please help me.

// The query is done, now we'll take the query results to do the data linking
function geometryQuery_Complete(featureSet) {
alert(featureSet.features.length);//Its showing length = 0
}

Thanks in advance,
Sowmya
0 Kudos
HemingZhu
Occasional Contributor III
Hi Hzhu,

  My problem is in posted code for only polygon feature featureset will be retrieved. For Line and point feature featureset will be always empty. How can i get those feature's objectID "onDrawEnd".

Please help me.

// The query is done, now we'll take the query results to do the data linking
function geometryQuery_Complete(featureSet) {
alert(featureSet.features.length);//Its showing length = 0
}

Thanks in advance,
Sowmya


Put alert into your function runGeometryQuery(geometry) to see if the returned geometry is a point or polyline. something like:
function runGeometryQuery(geometry)
{
   alert (geometry.type);
}

and then go from there to see if you get anything in your featureset...
0 Kudos
SowmyaK
New Contributor
Hi


          It will always give point as geometry since we are using Drawingtoolbar( <div dojotype="dijit.form.Button" id="select" style="background-image:images/hyperlink_1.gif" iconclass="images/hyperlink_1.gif"                               onclick="toolbar.activate(esri.toolbars.Draw.POINT)">Select</div>)
0 Kudos
HemingZhu
Occasional Contributor III
Hi Hzhu,

  My problem is in posted code for only polygon feature featureset will be retrieved. For Line and point feature featureset will be always empty. How can i get those feature's objectID "onDrawEnd".

Please help me.

// The query is done, now we'll take the query results to do the data linking
function geometryQuery_Complete(featureSet) {
alert(featureSet.features.length);//Its showing length = 0
}

Thanks in advance,
Sowmya


I think i know your problem now. you draw a point and then use that point to do a spatial query against the layer. Since you do not specify the query's spatialRelationship. The default is always SPATIAL_REL_INTERSECTS. So when you do a spatial query against a point or polyline layer, you would not get any results unless your query point touchs a point or line feature. My suggestion would be to specify the spatialRelationship to something other than SPATIAL_REL_INTERSECTS when you do query on point or polyline layer. Please let me know if you understand what i am saying or not.
0 Kudos
SowmyaK
New Contributor
Hi,

   I understood.I tried with all different spatialrelationships. Still it is not returning any fearure on querycomplete
0 Kudos
HemingZhu
Occasional Contributor III
Hi,

   I understood.I tried with all different spatialrelationships. Still it is not returning any fearure on querycomplete


Have you tried executeRelationshipQuery method. It will give me all the relationships that you can try on. Or buffer the query point so that the intersection makes sense. Or try to use identify task for the point of line feature by giving some value of tolerance. Those are just some of the suggestions... Hope it will help you.
0 Kudos
bradeckrose
New Contributor
The following line looks like it may be missing a /:
var queryTask = new esri.tasks.QueryTask(servicename+lyrind);


Can you do this instead?
var qturl = servicename+lyrind;
alert (qturl);
var queryTask = new esri.tasks.QueryTask(qt);

Just want to make sure you have a valid url to query.

brad
0 Kudos