+ Reply to Thread
Results 1 to 10 of 10

Thread: Spatial Reference undefined error when trying to buffer polygon

  1. #1
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Default Spatial Reference undefined error when trying to buffer polygon

    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!

    Code:
    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);
    	});
    }

  2. #2
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    What do you see in firebug or chrome dev tools if you put this in your bufferSelectedFeatures function:
    Code:
    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.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  3. #3
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    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

    Code:
    spatialRef = new esri.SpatialReference({wkid:2276});

  4. #4
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    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:
    Code:
    dojo.toJson(spatialRef)
    But it sounds like your spatial reference is correct.

    Is selectedFeatures an array? bufferParameters.geometries has to be an array.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  5. #5
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    Actually, I'm using Firefox and Firebug. The JSON is

    Code:
    {"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

    Code:
    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

  6. #6
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    Thanks. What does this show:
    Code:
    console.log("first feature's wkid: ", selectedFeatures[0].spatialReference.wkid);
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  7. #7
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    Undefined, if I use

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

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

  8. #8
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    1
    This post is marked as the answer

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    OK, cool, we're getting somewhere . It looks like selectedFeature is an array of graphics, not geometries. Try this:

    Code:
    var geoms = dojo.map(selectedFeatures, function(graphic) {
      return graphic.geometry;
    });
    bufferParams.geometries = geoms;
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  9. #9
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    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!

  10. #10
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: Spatial Reference undefined error when trying to buffer polygon

    Glad to help! Thanks for marking this thread answered as well.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts