2

I have a base map on top of which I have added a feature layer . I pull thousands of json data from my db which has lat/long information , then I create points using lat/long and I plot those points on map. Many points may be drawn on the feature layer(polygon).

I have to find common points which all fall on the feature layer, for this I used below approach similar to this: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Intersect/00080000000p000000/

function plotandfind() {
  var count=0;
  require(["dojo/parser", "dojo/_base/connect", "dojo/on",
    "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer",
    "esri/geometry/Extent", "esri/symbols/SimpleFillSymbol",
    "esri/symbols/SimpleLineSymbol", "dojo/_base/Color", "esri/graphic",
    "dojox/collections/Dictionary", "esri/geometry/Point", 
    "esri/symbols/SimpleMarkerSymbol", "esri/SpatialReference", 
    "esri/geometry/webMercatorUtils", "dojo/dom", "esri/tasks/query", 
    "dojo/domReady!" 
  ], function(
    parser, connect, on, ArcGISDynamicMapServiceLayer, FeatureLayer, Extent,
    SimpleFillSymbol, SimpleLineSymbol, Color, Graphic, Dictionary, Point,
    SimpleMarkerSymbol, SpatialReference, webMercatorUtils, Query
  ) {
    try{
      dojo.xhrGet({
        url:"q.json",
        handleAs:"json",
        load: function(data){
          console.log("data "+data[0].Admin1);

          dojo.forEach(data,function(locations){
            var wgs = new SpatialReference({ "wkid": 4326});
            var latlng = new  Point(parseFloat(locations.Longitude), parseFloat(locations.Latitude),wgs);
            var webMercator = webMercatorUtils.geographicToWebMercator(latlng);
            var geometry = new esri.geometry.Point(webMercator.x,webMercator.y,map.spatialReference);
            var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CROSS, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,0,0.25]));
            var attr = {"LOCATION_ID":data.Admin1};
            var graphic = new esri.Graphic(geometry, symbol,attr);

            map.graphics.add(graphic);
            var queryTask = new esri.tasks.QueryTask("http://10.97.43.4:6080/arcgis/rest/services/POC/Sandy_Hurricane_Forecast/MapServer/0");
            var query = new esri.tasks.Query();
            query.geometry=geometry;
            query.returnGeometry = true;
            query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
            queryTask.execute(query,function(featureSet){
              var resultFeatures = featureSet.features;

              //Loop through each feature returned
              for (var i=0, il=resultFeatures.length; i<il; i++) {
                count++;
              }
            });

          });

        },
        error:console.log("error")
      });

      console.log(" added point");
    }catch(e){
      console.log(" error adding point"+e);
    }
  });
} 

I will pass the point that I created as the query input to the feature layer and I will get to know whether it is resides in the polygon. Is this right way ?

The problem is what if I have millions of records, is this the right approach or is there a better way?

I tried your link, but I am not sure if I am doing the right thing. Just to reiterate, I have a polygon which I have to plot some points (only those points which fall in that polygon but I have millions of polygons). I have loaded all points as a feature layer now and did code as below. But I am facing an issue where I have loaded main feature to load points from server. I have loaded it as feature layer, but do I have to add feature layer? It will plot all points but I first need to get common points then add those points in the polygon.

// Layer url is the feature layer where points are loaded as polygon.
function plotPoints(layerUrl) {

  // this layer contains points 
  var count=0;
  require(["dojo/parser", "dojo/_base/connect", "dojo/on",
    "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer",
    "esri/geometry/Extent", "esri/symbols/SimpleFillSymbol",
    "esri/symbols/SimpleLineSymbol", "dojo/_base/Color", "esri/graphic",
    "dojox/collections/Dictionary", "esri/geometry/Point",
    "esri/symbols/SimpleMarkerSymbol", "esri/SpatialReference",
    "esri/geometry/webMercatorUtils", "dojo/dom", "esri/tasks/query", "dojo/domReady!"
  ], function(
    parser, connect, on, ArcGISDynamicMapServiceLayer, FeatureLayer, Extent,
    SimpleFillSymbol, SimpleLineSymbol, Color, Graphic, Dictionary, Point,
    SimpleMarkerSymbol, SpatialReference, webMercatorUtils, Query
  ) {
    try{
      featureLayer = new esri.layers.FeatureLayer(layerUrl,{
        mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
        outFields: ["*"],
        opacity:.75
      });
      map.addLayer(featureLayer);
      // once the featrue layer containing points i loaded i will find common points
      featureLayer.on("update-end",function(){
        loadPoints(featureLayer);
      });

      console.log(" added point");
    }catch(e){
      console.log(" error adding point"+e);
    }
  });
} 

function getCommonPoints(featureLayer) {
  try{
    console.log(" feature layer");

    // query task is the feature layer which has main polygon on top of which I have to plot some commonpoints
    queryTask = new esri.tasks.QueryTask("http://10.97.43.4:6080/arcgis/rest/services/POC/CAT_Events/MapServer/0");
    query = new esri.tasks.Query();
    var feature;
    var features = featureLayer.graphics;
    console.log(" features "+features);
    var inBuffer = [];
    //filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
    for (var i = 0; i < features.length; i++) {
      feature = features[i];
      inBuffer.push(feature.attributes[featureLayer.objectIdField]);
    }

    query.objectIds = inBuffer;
    query.returnGeometry = true;
    query.outSpatialReference = {wkid:4326}; 
    query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
    queryTask.execute(query,function(featureSet){
      var features = featureSet.features;
      for (var i = 0; i < features.length; i++) {
        feature = features[i];
        attributes = feature.attributes;
        console.log(" SOME FEATURES SELECTED ");
      }
    });
  }catch(e){
    console.log(" error occured  "+e);
  }
}
  • is your code work? is the problem with the outputs? – fkili mohamed Jun 16 '14 at 20:57
  • works , no problem with output either – VIckyb Jun 17 '14 at 8:56
2

i guess 'better' is subjective, but to me it seems like it would be substantially simpler to load the points into an ArcGIS Server or ArcGIS Online hosted service and pass the polygon in a query.

this would make it really straightforward to get a reference to only the points that fall within the polygon and do the heavy lifting server side.

check out this example https://developers.arcgis.com/javascript/jssamples/util_relation.html

|improve this answer|||||
  • I have millions of records , along with lat and log i have also some other values .Based on points of polygon which fall in other polygon i have to calculate other values .Currently i have these in DB would it be good to move to ARCGIS server ? and if i have to update some vales i have to update services will it be cumbersome – VIckyb Jun 20 '14 at 16:49
  • yup, registering the database with ArcGIS Server and publishing the data in a service would allow you to expose the content in web applications selectively. changes in the underlying data would be picked up by the service automatically. – John Gravois Jun 23 '14 at 4:44
  • I am trying to implement this , i have created a arcgis service with all the points as a single feature layer . Now how do i pass a a featuer layer as input in query task ? – VIckyb Jul 8 '14 at 14:00
  • 1
    here's a link to a sample which passes a Query and an individual layer in a map service to a QueryTask developers.arcgis.com/javascript/jssamples/query_hover.html here's a link to a sample which passes a Query to featureLayer.selectFeatures() instead developers.arcgis.com/javascript/jssamples/query_buffer.html – John Gravois Jul 8 '14 at 16:32
  • Please look at my question i have tried and described my problem. – VIckyb Jul 9 '14 at 14:24
0

Finally i was able to resolve the issue.

I have loaded all the points in my arcgis server and exposed services.I have my ploygon services too.

After plotting the ploygon , when i want to find common point i will load all points from my point server then i will pass each point geometry object to query of polygon server and check if result returns some features if yes then i will plot the point.

                    function getCommonPoints() {
                            var graphic, extent;
                            var queryTask = new esri.tasks.QueryTask(pointserverurl);
                            var query = new esri.tasks.Query();
                            var polyquery = new esri.tasks.Query();
                            var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
                            new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
                            new esri.Color([255, 0, 0]), 3), new esri.Color([125, 125, 125, 0.35]));
                            var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle("square").setColor(new esri.Color([255,0,0,0.5]));
                            query.outFileds = ["*"];
                            query.returnGeometry = true;
                            query.outSpatialReference = { "wkid": 4326 };
                            var whereclause="condition to get points";
                            query.where = whereclause;
                            query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
                            //query.geometry = evt.geometry;
                            queryTask.execute(query, function (featureSet) {

                                if (featureSet.features.length == 0) {
                                    alert("No Results found");
                                }
                                else {
                                    for (var i = 0; i < featureSet.features.length ; i++) {
                                        //Get the graphics from featureset
                                        graphic = featureSet.features[i];
                                        graphic.setSymbol(symbol);
                                        polyquery.outFileds = ["*"];
                                        polyquery.returnGeometry = false;
                                        polyquery.outSpatialReference = { "wkid": 4326 };
                                        polyquery.geometry = graphic.geometry
                                        polyquery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;
                                        console.log(" comparing "+graphic.attributes.GGRPHC_AR_ID);
                                        //console.log(" adding graphic");
                                        //map.graphics.add(graphic);*/

                                        addCommonPoints(polyquery,graphic);

                                    }
                                }
                            });
                    }

function addCommonPoints(polyquery,graphic)
 {
  EventsfeatureLayer.queryFeatures(polyquery, function (featureSet2) {
        console.log(" feaureset from events layers "+featureSet2.features.length);
        if (featureSet2.features.length > 0) {
            console.log(" adding graphics"+graphic.attributes.GGRPHC_AR_ID);
            map.graphics.add(graphic);
        }
  });
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.