Select to view content in your preferred language

Reproject a Graphic from 102100 to 4326

4986
12
Jump to solution
09-25-2015 09:07 AM
FlorianCADOZ
Regular Contributor

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 !

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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

}

View solution in original post

12 Replies
RobertScheitlin__GISP
MVP Emeritus

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
  }
});
FlorianCADOZ
Regular Contributor

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...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florian,

   So using contains boolean return you can add that point or the points attributes to an array if true then.

FlorianCADOZ
Regular Contributor

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 !

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florian,

   I would have to see your code and what object you are trying to use the contains method on.

0 Kudos
FlorianCADOZ
Regular Contributor

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 :

Sans titre2.png

The poly's variable look like this :

Sans titre.png

On the map, it look like this :

Sans titre3.png

This is not the same projection but the datas are overlaying correctly...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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"

0 Kudos
FlorianCADOZ
Regular Contributor

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

        }

    },

});

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florian,

   So you have two problems in your code then.

  1. var poly = graphicsUtils.getGeometries([this.spatialFilter4Analysis.graphics[2]]); means that poly is not a polygon object, it is an array.
  2. var points = [this.entry4Analysis.featureSet.features]; means that points is an array as well and contain is only expecting one point.

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;