Select to view content in your preferred language

''wkid' undefined' error message for buffer polygon

2981
4
Jump to solution
12-05-2015 11:38 PM
LefterisKoumis
Frequent Contributor

This error consumed me some time and I can't see the problem that brings the wkid error.

At first, a buffer is drawn around a line (identified as gra below), then I use the buffer polygon to capture any features from the feature service that are located within the buffer polygon. The buffer is drawn around the line, but the second query brings the error. Suggestions? Thank you.

getthelinebuffer: function(){

   mysymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255,0,0]), 2), new Color([255,255,0,0.25]));

 

  var resultEvent;

  geodesicBuffer.distances = [1];

  geodesicBuffer.geometries = [gra.geometry];

  geodesicBuffer.unit = bufferunit;

  geodesicBuffer.outSpatialReference = this.map.spatialReference;

  geodesicBuffer.geodesic = true;

  geodesicBuffer.unionResults = true;

  esriConfig.defaults.geometryService.buffer(geodesicBuffer, lang.hitch(this, function (evt) {

  resultEvent = evt[0];

  geodesicUserGraphic = new Graphic(Polygon, mysymbol);

------

  }));

  geodesicUserGraphic.geometry = resultEvent;

   bufferGraphicsLayer.add(geodesicUserGraphic);

          

          }));

 

   this.map.addLayer(bufferGraphicsLayer);

   var featureLayer = new FeatureLayer("xxxxx/0");

  var myquery = new Query();

          myquery.geometry = [resultEvent];

   myquery.returnGeometry=true;

   myquery.outFields=["X", "Y"];

    myquery.spatialRelationship = "esriSpatialRelIntersects";

 

   featureLayer.queryFeatures(myquery, this.selectInBuffer);

  },

selectInBuffer:function(){

------

},

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  You have a couple of issues in your code. One is the query is executing before the buffer is done and thus no geometry for the query. Next is that you are using two fields that are not in your layer you are using (county does not exist but County does and schools is not in that layer at all).

getthelinebuffer: function () {
        var mysymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25]));
        var resultEvent;
        this.geodesicBuffer.distances = [1];
        this.geodesicBuffer.geometries = [this.gra.geometry];
        this.geodesicBuffer.unit = this.bufferunit;
        this.geodesicBuffer.outSpatialReference = this.map.spatialReference;
        this.geodesicBuffer.geodesic = true;
        this.geodesicBuffer.unionResults = true;

        esriConfig.defaults.geometryService.buffer(this.geodesicBuffer, lang.hitch(this, function (evt) {
          resultEvent = evt[0];
          var geodesicUserGraphic = new Graphic(resultEvent, mysymbol, {
            "name": "Buffer"
          });
          this.ctxMenuForBuffer = new Menu({});
          this.ctxMenuForBuffer.addChild(new MenuItem({
            label: "Delete Buffer",
            onClick: lang.hitch(this, function () {
              this.bufferGraphicsLayer.clear();
              this._clearall();
            })
          }));
          this.ctxMenuForBuffer.startup();
          this.bufferGraphicsLayer.add(geodesicUserGraphic);

          var featureLayer = new FeatureLayer("https://map.dfg.ca.gov/arcgis/rest/services/Project_PAD/PAD/MapServer/0");
          var myquery = new Query();
          myquery.geometry = resultEvent;
          myquery.returnGeometry = true;
          myquery.outFields = ["StreamName", "County"];
          myquery.outSpatialReference = this.map.spatialReference;
          myquery.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
          featureLayer.queryFeatures(myquery, this.selectInBuffer);
        }));

        this.map.addLayer(this.bufferGraphicsLayer);

        on(this.bufferGraphicsLayer, 'mouse-over', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "Buffer") {
            this.selectedGraphic = evt.graphic;
            this.ctxMenuForBuffer.bindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
        on(this.bufferGraphicsLayer, 'mouse-out', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "Buffer") {
            this.ctxMenuForBuffer.unBindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
      },

      selectInBuffer: function (results) {
        var resultItems = [];
        var resultCount = results.features.length;
        for (var i = 0; i < resultCount; i++) {
          var featureAttributes = results.features.attributes;
          for (var attr in featureAttributes) {
            console.log(featureAttributes[attr]);
          }
        }
      },

      createcontextmenu: function () {
        var ctxMenuForGraphics = new Menu({});
        ctxMenuForGraphics.addChild(new MenuItem({
          label: "info",
          onClick: lang.hitch(this, function (evt) {
            console.info(evt);
          })
        }));

        ctxMenuForGraphics.addChild(new MenuItem({
          label: "Delete",
          onClick: lang.hitch(this, function (evt) {
            console.info(evt);
          })
        }));
        ctxMenuForGraphics.startup();

        on(this.myGraphicsLayer, 'mouse-over', lang.hitch(this, function (evt) {
          this.map.graphics.clear();
          if (evt.graphic.attributes.name === "my point") {
            this.selectedGraphic = evt.graphic;
            ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));

        on(this.myGraphicsLayer, 'mouse-out', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "my point") {
            ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
      }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  This line looks wrong.

myquery.geometry = [resultEvent];

The Query object is not expecting an array of geometries it is expecting a single geometry.

Also your omission of parts of your code for brevity sake, make it hard to diagnose as well.

0 Kudos
LefterisKoumis
Frequent Contributor

Thank you Robert.  Actually, the resultEvent is a single geometry. Prior to that line resultEvent = evt[0] which is single element in the array, a signle geometry.  Here is the complete code. I changed the line myquery.geometry = [resultEvent]; to myquery.geometry = resultEvent; since it is already an element of an array. The error I get now is the dojo.io.script error. Also, how can I insert the code in this forum with the line numbers?

startup: function() {

  this.inherited(arguments);

  bufferGraphicsLayer = new GraphicsLayer();

  bufferunit= GeometryService.UNIT_STATUTE_MILE;

  geodesicBuffer =new BufferParameters();

  console.log('startup');

  var pA= [];

  pA.push(new Point(-121.1012319,  38.956273, map.SpatialReference));

  pA.push(new Point(-121.07462622,  38.90015662, map.SpatialReference));

 

  myGraphicsLayer = new GraphicsLayer();

  pLine=new Polyline(map.SpatialReference);

  pLine.addPath(pA);

  var lineSymbol = new SimpleLineSymbol(

  SimpleLineSymbol.STYLE_SOLID,

  new Color([255,0,0]),

  4

  );

  this.map.graphics.clear();

  gra=new Graphic(pLine, lineSymbol);

 

  myGraphicsLayer.add(gra);

  this.map.addLayer(myGraphicsLayer);

  var extent = new esri.geometry.Extent(-121.1012319,  38.956273, -121.07462622,  38.90015662, map.SpatialReference);

  extent=extent.expand(4.0);

  this.map.setExtent(extent);

  this.getthelinebuffer();

    },

  getthelinebuffer: function(){

   mysymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255,0,0]), 2), new Color([255,255,0,0.25]));

 

  var resultEvent;

  geodesicBuffer.distances = [1];

  geodesicBuffer.geometries = [gra.geometry];

  geodesicBuffer.unit = bufferunit;

  geodesicBuffer.outSpatialReference = this.map.spatialReference;

  geodesicBuffer.geodesic = true;

  geodesicBuffer.unionResults = true;

  esriConfig.defaults.geometryService.buffer(geodesicBuffer, lang.hitch(this, function (evt) {

  resultEvent = evt[0];

  geodesicUserGraphic = new Graphic(Polygon, mysymbol);

  geodesicUserGraphic.geometry = resultEvent;

  geodesicUserGraphic.symbol = mysymbol;

  bufferGraphicsLayer.add(geodesicUserGraphic);

          

          }));

 

   this.map.addLayer(bufferGraphicsLayer);

   var featureLayer = new FeatureLayer("https://map.dfg.ca.gov/arcgis/rest/services/Project_PAD/PAD/MapServer/0");

  var myquery = new Query();

          myquery.geometry = resultEvent;

   myquery.returnGeometry=true;

   myquery.outFields=["school", "county"];

   myquery.outSpatialReference= this.map.spatialReference;

    myquery.spatialRelationship = "esriSpatialRelIntersects";

 

   featureLayer.queryFeatures(myquery, this.selectInBuffer);

  },

  selectInBuffer:function(results){

          var resultItems = [];

          var resultCount = results.features.length;

          for (var i = 0; i < resultCount; i++) {

            var featureAttributes = results.features.attributes;

            for (var attr in featureAttributes) {

             console.log(featureAttributes[attr]);

            }          

          }

    },

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  You have a couple of issues in your code. One is the query is executing before the buffer is done and thus no geometry for the query. Next is that you are using two fields that are not in your layer you are using (county does not exist but County does and schools is not in that layer at all).

getthelinebuffer: function () {
        var mysymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25]));
        var resultEvent;
        this.geodesicBuffer.distances = [1];
        this.geodesicBuffer.geometries = [this.gra.geometry];
        this.geodesicBuffer.unit = this.bufferunit;
        this.geodesicBuffer.outSpatialReference = this.map.spatialReference;
        this.geodesicBuffer.geodesic = true;
        this.geodesicBuffer.unionResults = true;

        esriConfig.defaults.geometryService.buffer(this.geodesicBuffer, lang.hitch(this, function (evt) {
          resultEvent = evt[0];
          var geodesicUserGraphic = new Graphic(resultEvent, mysymbol, {
            "name": "Buffer"
          });
          this.ctxMenuForBuffer = new Menu({});
          this.ctxMenuForBuffer.addChild(new MenuItem({
            label: "Delete Buffer",
            onClick: lang.hitch(this, function () {
              this.bufferGraphicsLayer.clear();
              this._clearall();
            })
          }));
          this.ctxMenuForBuffer.startup();
          this.bufferGraphicsLayer.add(geodesicUserGraphic);

          var featureLayer = new FeatureLayer("https://map.dfg.ca.gov/arcgis/rest/services/Project_PAD/PAD/MapServer/0");
          var myquery = new Query();
          myquery.geometry = resultEvent;
          myquery.returnGeometry = true;
          myquery.outFields = ["StreamName", "County"];
          myquery.outSpatialReference = this.map.spatialReference;
          myquery.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
          featureLayer.queryFeatures(myquery, this.selectInBuffer);
        }));

        this.map.addLayer(this.bufferGraphicsLayer);

        on(this.bufferGraphicsLayer, 'mouse-over', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "Buffer") {
            this.selectedGraphic = evt.graphic;
            this.ctxMenuForBuffer.bindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
        on(this.bufferGraphicsLayer, 'mouse-out', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "Buffer") {
            this.ctxMenuForBuffer.unBindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
      },

      selectInBuffer: function (results) {
        var resultItems = [];
        var resultCount = results.features.length;
        for (var i = 0; i < resultCount; i++) {
          var featureAttributes = results.features.attributes;
          for (var attr in featureAttributes) {
            console.log(featureAttributes[attr]);
          }
        }
      },

      createcontextmenu: function () {
        var ctxMenuForGraphics = new Menu({});
        ctxMenuForGraphics.addChild(new MenuItem({
          label: "info",
          onClick: lang.hitch(this, function (evt) {
            console.info(evt);
          })
        }));

        ctxMenuForGraphics.addChild(new MenuItem({
          label: "Delete",
          onClick: lang.hitch(this, function (evt) {
            console.info(evt);
          })
        }));
        ctxMenuForGraphics.startup();

        on(this.myGraphicsLayer, 'mouse-over', lang.hitch(this, function (evt) {
          this.map.graphics.clear();
          if (evt.graphic.attributes.name === "my point") {
            this.selectedGraphic = evt.graphic;
            ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));

        on(this.myGraphicsLayer, 'mouse-out', lang.hitch(this, function (evt) {
          if (evt.graphic.attributes.name === "my point") {
            ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode());
          }
        }));
      }
0 Kudos
LefterisKoumis
Frequent Contributor

Thank you. As far as the fields, I previously changed feature layer url, but I forgot to change the outfields.

0 Kudos