Hey guys, I have an array of geometries and im trying to union them together to do a query.
this is my code: Edit fiddle - JSFiddle line 683 is where the function in question is located.
the error I get is
Uncaught TypeError: Cannot read property 'wkid' of undefined
Any idea what Im doing wrong? is it a spatial reference issue?
Solved! Go to Solution.
Ibrahim,
GeometryService Union method is not instantaneous. It requires a call back function before you can use the results.
var gs = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
gs.union(geometry);
query.geometry = gs;
Basically in your code above you are sending the GeometryService to the query.geometry and not the results of the union.
Try something like this:
var gs = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); gs.union(geometry, function(results){ query.geometry = results; query.outFields = ["*"]; myQueryTask.execute(query, censusGrid); });
Ibrahim,
GeometryService Union method is not instantaneous. It requires a call back function before you can use the results.
var gs = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
gs.union(geometry);
query.geometry = gs;
Basically in your code above you are sending the GeometryService to the query.geometry and not the results of the union.
Try something like this:
var gs = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); gs.union(geometry, function(results){ query.geometry = results; query.outFields = ["*"]; myQueryTask.execute(query, censusGrid); });
Yup, thanks added a callback and error function. thanks for catching that.
Hey Ibrahim,
It's not a spatial reference issue (even though it's looking for one), but a type error being returned from the ESRI GeometryService. The input of the GeometryService Union operation is an array of geometries to perform the union on. Each geometry must be of the same type (point, multipoint, polyline or polygon), and in your case I can't exactly tell for sure what you're using - but my first guess would be polylines and polygons? Either way, something to check, as that's what the error message is hinting at.
More info at:
Cheers,
Todd