Spatial Reference undefined error when trying to buffer polygon

4067
9
Jump to solution
05-03-2012 09:03 AM
ShawnHolyoak
Occasional Contributor
I'm trying to buffer a polygon in my map, and I keep getting an "_a94[0].spatialReference is undefined" error from the 2.8 api js file.  I've verified that the spatialRef var is an actual spatial reference object.  I've verified that I have a valid geometry in that same spatial reference.  I've verified that my geometry service actually will return a polygon when buffering (though I've admittedly only tested a point that way).  My geoms var in my callback function always returns undefined.  I don't understand what's going on.  My code is below:

I call initializeBuffer on load.  Then bufferSelectedFeatures is called when the toolbar button is clicked.

Please help!

function initializeBuffer() {  bufferSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color("#234483")), new dojo.Color([0,255,0],0.25));  geomSvc = esri.config.defaults.geometryService;    bufferParams = new esri.tasks.BufferParameters();  bufferParams.unionResults = true;  bufferParams.unit = esri.tasks.GeometryService.UNIT_FOOT; }  function bufferSelectedFeatures() {  bufferParams.bufferSpatialReference = spatialRef;  bufferParams.outSpatialReference = spatialRef;  bufferParams.geometries = selectedFeatures;  var distances = [];  //TODO:change this to get the distance from the user  distances[0] = 200;  bufferParams.distances = distances;  geomSvc.buffer(bufferParams, bufferComplete); }  function bufferComplete(geoms) {  //convert geometries to graphics  dojo.forEach(geoms, function(geom){   var graphic = new esri.Graphic(geom, bufferSymbol);   map.graphics.add(graphic);  }); }
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
OK, cool, we're getting somewhere :). It looks like selectedFeature is an array of graphics, not geometries. Try this:

var geoms = dojo.map(selectedFeatures, function(graphic) {   return graphic.geometry; }); bufferParams.geometries = geoms;

View solution in original post

0 Kudos
9 Replies
derekswingley1
Frequent Contributor
What do you see in firebug or chrome dev tools if you put this in your bufferSelectedFeatures function:
console.log("selected features: ", selectedFeatures);


selectedFeatures needs to be an array. Also confirm that each selected feature has a spatial reference and please post the JSON for that represents your spatial reference.
0 Kudos
ShawnHolyoak
Occasional Contributor
I get [object Object] in the console.  I've verified my selected feature has the exact same wkid spatial reference as the bufferParams, 2276.  I'm not sure what you mean by posting the JSON for my spatial reference.  I'm setting it on load

spatialRef = new esri.SpatialReference({wkid:2276});
0 Kudos
derekswingley1
Frequent Contributor
Sounds like you're using IE...Chrome and Firefox + Firebug give you more detailed info.

For the spatialReference JSON, you can do something like this in the console:
dojo.toJson(spatialRef)


But it sounds like your spatial reference is correct.

Is selectedFeatures an array? bufferParameters.geometries has to be an array.
0 Kudos
ShawnHolyoak
Occasional Contributor
Actually, I'm using Firefox and Firebug.  The JSON is

{"wkid":2276,"wkt":null,"_info":{"3857":{"wkTemplate":"PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",${Central_Meridian}],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0]]","valid":[-20037508.342788905,20037508.342788905],"origin":[-20037508.342787,20037508.342787],"dx":0.00001},"4326":{"wkTemplate":"GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",${Central_Meridian}],UNIT[\"Degree\",0.0174532925199433]]","altTemplate":"PROJCS[\"WGS_1984_Plate_Carree\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Plate_Carree\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",${Central_Meridian}],UNIT[\"Degrees\",111319.491]]","valid":[-180,180],"origin":[-180,180],"dx":0.00001},"102100":{"wkTemplate":"PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",${Central_Meridian}],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0]]","valid":[-20037508.342788905,20037508.342788905],"origin":[-20037508.342787,20037508.342787],"dx":0.00001},"102113":{"wkTemplate":"PROJCS[\"WGS_1984_Web_Mercator\",GEOGCS[\"GCS_WGS_1984_Major_Auxiliary_Sphere\",DATUM[\"D_WGS_1984_Major_Auxiliary_Sphere\",SPHEROID[\"WGS_1984_Major_Auxiliary_Sphere\",6378137.0,0.0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",${Central_Meridian}],PARAMETER[\"Standard_Parallel_1\",0.0],UNIT[\"Meter\",1.0]]","valid":[-20037508.342788905,20037508.342788905],"origin":[-20037508.342787,20037508.342787],"dx":0.00001}},"declaredClass":"esri.SpatialReference"}


selectedFeatures is an array.  I checked in Chrome and I get a bit more information on the error.  It says

Uncaught TypeError: Cannot read property 'wkid' of undefined
dojo.declare.toJson                     serverapi.arcgisonline.com:48
dojo.declare.buffer                      serverapi.arcgisonline.com:48
bufferSelectedFeatures                buffer.js:30
bufferFeatures                           layout.js:403
onClick
dojo.declare._onClick                   serverapi.arcgisonline.com:48
dojo.declare._onButtonClick          serverapi.arcgisonline.com:48
dojo.hitch
0 Kudos
derekswingley1
Frequent Contributor
Thanks. What does this show:
console.log("first feature's wkid: ", selectedFeatures[0].spatialReference.wkid);
0 Kudos
ShawnHolyoak
Occasional Contributor
Undefined, if I use

console.log("First feature's spatial reference: " + selectedFeatures[0].spatialReference.wkid);


If I use

console.log("First feature's spatial reference: " + selectedFeatures[0].geometry.spatialReference.wkid);


I get 2276.
0 Kudos
derekswingley1
Frequent Contributor
OK, cool, we're getting somewhere :). It looks like selectedFeature is an array of graphics, not geometries. Try this:

var geoms = dojo.map(selectedFeatures, function(graphic) {   return graphic.geometry; }); bufferParams.geometries = geoms;
0 Kudos
ShawnHolyoak
Occasional Contributor
Indeed, that was it.  I'm going to research why that is, but at least I now have a buffer around my selected feature.  Thanks for your help!
0 Kudos
derekswingley1
Frequent Contributor
Glad to help! Thanks for marking this thread answered as well.
0 Kudos