Geometry union for a query

4533
3
Jump to solution
05-11-2015 05:29 AM
IbrahimHussein
Occasional Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

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);
        });
IbrahimHussein
Occasional Contributor

Yup, thanks added a callback and error function. thanks for catching that.

0 Kudos
ToddBlanchette
Occasional Contributor II

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:

ArcGIS REST API

Cheers,

Todd