Hello,
Here I have two graphics ( one is a polygon and the other one is compound of several points ) and my objective is to produce something that looks like this: ArcGIS API for JavaScript Sandbox
My problem is that the polygon is in 4326 , the map is apparently (not sure ) in 102100 , and the points are in 4326 and apparently I have a problem when using this function:
relationParams.geometries1 = graphicsUtils.getGeometries([this.entry4Analysis.featureSet.features[0]]);
relationParams.geometries2 = graphicsUtils.getGeometries([this.spatialFilter4Analysis.graphics[2]]);
relationParams.relation = RelationParameters.SPATIAL_REL_WITHIN;
this.geometryService.relation(relationParams, this.addRelateResultsToMap);
So I tried different syntax (like : .setOutSpatialReference) to change the projection of one or other of the graphics when I launch the spatial analysis but nothing happens...
So now I really need help...
Thank you very much by advance !
Solved! Go to Solution.
Florian,
Since your points are 102100 and your Poly is 4326 you can just use esri/geometry/webMercatorUtils to project your points to geographic (4326) before you try the poly.contains.
var point = webMercatorUtils.webMercatorToGeographicthis.entry4Analysis.featureSet.features[0].geometry);
if(poly.contains(point)){
alert('hello');
}
Florain,
It sounds like you do not even have to use the GeometryService for this as it looks like all you want to do is see if the polygon contains the points.
var poly = this.entry4Analysis.featureSet.features[0].geometry; array.map(yourPointsArray, function(pnt){ if(poly.contains(pnt)){ //now do something with that point like change it's symbol } });
Hello Robert and thank you for your answer !
I had alreally seen the polygon and his contains'function but in the documentation (here) the returned answer seems to be a boolean and I need to keed the different attributes of my array of point...
Florian,
So using contains boolean return you can add that point or the points attributes to an array if true then.
oh ok ! I tried the .contains() function the only response I get is something like "this function doesn't exist" ! I searched for some sample but I didn't find anything... I don't understand where is the problem !
(I specified define (["esri/geometry/Polygon", ...] and functino ( Polygon ...) and my geometries seems to be ok !
Florian,
I would have to see your code and what object you are trying to use the contains method on.
For now, I'm just trying to do something really simple !
My code looks like this :
if(poly.contains(points)){
alert('hello');
}
The points' variable look like this :
The poly's variable look like this :
On the map, it look like this :
This is not the same projection but the datas are overlaying correctly...
Florian,
I tried the .contains() function the only response I get is something like "this function doesn't exist"
So I need to see some code where you define your variable "poly"
Oh ok sorry, I'll try to simplify it a lttle before but I'm not sur it will really help you ! I gave you the objects' definition of the different datas because this is the more explicit that I can give you ! The data come from shapefile or are generate by other widgets...
My code look like this :
define([
..., "esri/geometry/Polygon", ...
],
function(
..., Polygon, ...
){
return declare([BaseWidget,_WidgetsInTemplateMixin],{
baseClass: 'jimu-widget-geochart',
name: 'Geochart',
urlServer: '',
itemSelector: null,
entry4Analysis: null,
entryAttrib4Analysis: null,
spatialFilter4Analysis: null,
geometryService: null,
postCreate: function() {
this.inherited(arguments);
this._loadConfig();
console.log('postCreate');
this._initListeners();
this._initFilterLayer();
this._initAnalysis();
},
_loadConfig: function () {
this.arcgisServerURL = this.config.arcgisServerURL;
},
[...some code calling external data...]
onApplyFilter: function (evt){
var poly = graphicsUtils.getGeometries([this.spatialFilter4Analysis.graphics[2]]);
var points = [this.entry4Analysis.featureSet.features];
if(poly.contains(points)){
alert('hello');
}
},
});
Florian,
So you have two problems in your code then.
I am not sure why you are using graphicsUtils.getGeometries([this.spatialFilter4Analysis.graphics[2]]); since you are specifying a particular geometry when you use [2]. I would use:
var poly = this.spatialFilter4Analysis.graphics[2].geometry;