<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Find Nearest features of one layer to another in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/find-nearest-features-of-one-layer-to-another/m-p/455627#M42104</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks so much to Ryan Sellman and Robert Scheitlin for their HUGE help. Below is my working code. I have the buffer distance hard-coded but plan to use an insert value. Use of the geometryEngine is a wonderful way to create buffers and have them union into a single polygon. The JS code below lets the user select points from FeatureLayer1, those selected points then get buffered (500 feet in this case). That buffer is then used to query and select any intersecting points from FeatureLayer2. Some incredibly handy functionality.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//&amp;lt;&amp;lt;&amp;lt;BUFFER OF SELECTED POINTS THEN SELECTS ANOTHER LAYER'S POINTS&amp;gt;&amp;gt;&amp;gt;


//Draw Day 1 tool initialization function
map.on("load", initDrawToolTest);


function initDrawToolTest(evt) {
tbDrawTest = new Draw(evt.map);
tbDrawTest.on("draw-end", displayPolygonTest);
}


//Draw Freehand Polygon for FeatureLayer1
on(dom.byId("TestSelect"), "click", function () {
tbDrawTest.activate(Draw.FREEHAND_POLYGON);
});


//Get geometry from FeatureLayer1 drawn polygon, symbolize polygon, start FeatureLayer1 query 
function displayPolygonTest(evt) {
// Get the geometry from the event object
var geometryInput = evt.geometry;
// Define symbol for finished polygon
var tbDrawSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([53, 119, 221]), 2), new Color([53, 119, 221, 0.3]));
map.graphics.clear();
var graphicPolygon = new Graphic(geometryInput, tbDrawSymbol);
map.graphics.add(graphicPolygon);
selectDay1ActivitiesTest(geometryInput); // Call the next function below...vvv
}


//Symbolize FeatureLayer1, create new Query, select features
function selectDay1ActivitiesTest(geometryInput) {
// Define symbol for selected features (using JSON syntax for improved readability)
var symbolSelectedTest = new SimpleMarkerSymbol({
&amp;nbsp; "type": "esriSMS",
&amp;nbsp; "style": "esriSMSCircle",
&amp;nbsp; "color": [255, 115, 0, 128],
&amp;nbsp; "size": 6,
&amp;nbsp; "outline": {
&amp;nbsp; "color": [255, 0, 0, 214],
&amp;nbsp; "width": 1
&amp;nbsp; }
});


//Set the selection symbol to FeatureLayer1
FeatureLayer1.setSelectionSymbol(symbolSelectedTest);
//Initialize the query
var queryDay1ActivitiesTest = new Query();
tbDrawTest.deactivate(); //turns off selection tool so it does not stay on in map.
queryDay1ActivitiesTest.geometry = geometryInput;
//Wire the layer's selection complete event, call function to populate grid with selection results
FeatureLayer1.on("selection-complete", populateGrid1);
//Day 1 Activities selection
FeatureLayer1.selectFeatures(queryDay1ActivitiesTest, FeatureLayer.SELECTION_NEW, function (features, selectionMethod) {


&amp;nbsp; //Create buffer of selection
&amp;nbsp; var selectedGeoms = graphicsUtils.getGeometries(features);
&amp;nbsp; var distance = [500];
&amp;nbsp; var bufferedGeometries = geometryEngine.geodesicBuffer(selectedGeoms, distance, GeometryService.UNIT_FOOT, true);


&amp;nbsp; var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
&amp;nbsp; new Color([0, 0, 255, 0.65]), 2
&amp;nbsp; ),
&amp;nbsp; new Color([0, 0, 255, 0.35])
&amp;nbsp; );


&amp;nbsp; array.map(bufferedGeometries, function (geometry) {
&amp;nbsp; var graphic = new Graphic(geometry, symbol);
&amp;nbsp; map.graphics.add(graphic);
&amp;nbsp; });


&amp;nbsp; //Variable represents Query area to select intersecting FeatureLayer2 points
&amp;nbsp; var geoBuffer = geometryEngine.union(bufferedGeometries);


&amp;nbsp; //Symbolize FeatureLayer2 selection
&amp;nbsp; var symbolSelected = new PictureMarkerSymbol({
&amp;nbsp; "type": "esriPMS",
&amp;nbsp; "url": "images/coffeeselect.png",
&amp;nbsp; "contentType": "image/png",
&amp;nbsp; "width": 20,
&amp;nbsp; "height": 22
&amp;nbsp; });
&amp;nbsp; symbolSelected.setOffset(-1, 0);


&amp;nbsp; //Set the selection symbol to FeatureLayer2
&amp;nbsp; FeatureLayer2.setSelectionSymbol(symbolSelected);
&amp;nbsp; //Select FeatureLayer2 points that intersect buffer
&amp;nbsp; var querySBTest = new Query();
&amp;nbsp; querySBTest.geometry = geoBuffer;
&amp;nbsp; querySBTest.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
&amp;nbsp; //Wire the layer's selection complete event, call function to populate grid with selection results
&amp;nbsp; FeatureLayer2.on("selection-complete", populateGrid2);
&amp;nbsp; //FeatureLayer2 selection
&amp;nbsp; FeatureLayer2.selectFeatures(querySBTest, FeatureLayer.SELECTION_NEW);


});
};&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:18:50 GMT</pubDate>
    <dc:creator>DavidChrest</dc:creator>
    <dc:date>2021-12-11T20:18:50Z</dc:date>
    <item>
      <title>Find Nearest features of one layer to another</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/find-nearest-features-of-one-layer-to-another/m-p/455626#M42103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there some kind of example that essentially mimics the ArcToolbox Near tool? I essentially need to select points of one layer that are closes to points of another layer. Some kind of query by distance would also work (select points within x meters of a layer). I don't want to use the FindNearest Analysis widget since it uses up credits and no examples exist on the API site. Is there some way to make this happen? Near or select by distance would be great! Or do I need to create a geoprocessing service utilizing the ArcToolbox Near tool?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much for any help or information. It is much appreciated.&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 16:36:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/find-nearest-features-of-one-layer-to-another/m-p/455626#M42103</guid>
      <dc:creator>DavidChrest</dc:creator>
      <dc:date>2015-11-17T16:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Find Nearest features of one layer to another</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/find-nearest-features-of-one-layer-to-another/m-p/455627#M42104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks so much to Ryan Sellman and Robert Scheitlin for their HUGE help. Below is my working code. I have the buffer distance hard-coded but plan to use an insert value. Use of the geometryEngine is a wonderful way to create buffers and have them union into a single polygon. The JS code below lets the user select points from FeatureLayer1, those selected points then get buffered (500 feet in this case). That buffer is then used to query and select any intersecting points from FeatureLayer2. Some incredibly handy functionality.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//&amp;lt;&amp;lt;&amp;lt;BUFFER OF SELECTED POINTS THEN SELECTS ANOTHER LAYER'S POINTS&amp;gt;&amp;gt;&amp;gt;


//Draw Day 1 tool initialization function
map.on("load", initDrawToolTest);


function initDrawToolTest(evt) {
tbDrawTest = new Draw(evt.map);
tbDrawTest.on("draw-end", displayPolygonTest);
}


//Draw Freehand Polygon for FeatureLayer1
on(dom.byId("TestSelect"), "click", function () {
tbDrawTest.activate(Draw.FREEHAND_POLYGON);
});


//Get geometry from FeatureLayer1 drawn polygon, symbolize polygon, start FeatureLayer1 query 
function displayPolygonTest(evt) {
// Get the geometry from the event object
var geometryInput = evt.geometry;
// Define symbol for finished polygon
var tbDrawSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([53, 119, 221]), 2), new Color([53, 119, 221, 0.3]));
map.graphics.clear();
var graphicPolygon = new Graphic(geometryInput, tbDrawSymbol);
map.graphics.add(graphicPolygon);
selectDay1ActivitiesTest(geometryInput); // Call the next function below...vvv
}


//Symbolize FeatureLayer1, create new Query, select features
function selectDay1ActivitiesTest(geometryInput) {
// Define symbol for selected features (using JSON syntax for improved readability)
var symbolSelectedTest = new SimpleMarkerSymbol({
&amp;nbsp; "type": "esriSMS",
&amp;nbsp; "style": "esriSMSCircle",
&amp;nbsp; "color": [255, 115, 0, 128],
&amp;nbsp; "size": 6,
&amp;nbsp; "outline": {
&amp;nbsp; "color": [255, 0, 0, 214],
&amp;nbsp; "width": 1
&amp;nbsp; }
});


//Set the selection symbol to FeatureLayer1
FeatureLayer1.setSelectionSymbol(symbolSelectedTest);
//Initialize the query
var queryDay1ActivitiesTest = new Query();
tbDrawTest.deactivate(); //turns off selection tool so it does not stay on in map.
queryDay1ActivitiesTest.geometry = geometryInput;
//Wire the layer's selection complete event, call function to populate grid with selection results
FeatureLayer1.on("selection-complete", populateGrid1);
//Day 1 Activities selection
FeatureLayer1.selectFeatures(queryDay1ActivitiesTest, FeatureLayer.SELECTION_NEW, function (features, selectionMethod) {


&amp;nbsp; //Create buffer of selection
&amp;nbsp; var selectedGeoms = graphicsUtils.getGeometries(features);
&amp;nbsp; var distance = [500];
&amp;nbsp; var bufferedGeometries = geometryEngine.geodesicBuffer(selectedGeoms, distance, GeometryService.UNIT_FOOT, true);


&amp;nbsp; var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
&amp;nbsp; new Color([0, 0, 255, 0.65]), 2
&amp;nbsp; ),
&amp;nbsp; new Color([0, 0, 255, 0.35])
&amp;nbsp; );


&amp;nbsp; array.map(bufferedGeometries, function (geometry) {
&amp;nbsp; var graphic = new Graphic(geometry, symbol);
&amp;nbsp; map.graphics.add(graphic);
&amp;nbsp; });


&amp;nbsp; //Variable represents Query area to select intersecting FeatureLayer2 points
&amp;nbsp; var geoBuffer = geometryEngine.union(bufferedGeometries);


&amp;nbsp; //Symbolize FeatureLayer2 selection
&amp;nbsp; var symbolSelected = new PictureMarkerSymbol({
&amp;nbsp; "type": "esriPMS",
&amp;nbsp; "url": "images/coffeeselect.png",
&amp;nbsp; "contentType": "image/png",
&amp;nbsp; "width": 20,
&amp;nbsp; "height": 22
&amp;nbsp; });
&amp;nbsp; symbolSelected.setOffset(-1, 0);


&amp;nbsp; //Set the selection symbol to FeatureLayer2
&amp;nbsp; FeatureLayer2.setSelectionSymbol(symbolSelected);
&amp;nbsp; //Select FeatureLayer2 points that intersect buffer
&amp;nbsp; var querySBTest = new Query();
&amp;nbsp; querySBTest.geometry = geoBuffer;
&amp;nbsp; querySBTest.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
&amp;nbsp; //Wire the layer's selection complete event, call function to populate grid with selection results
&amp;nbsp; FeatureLayer2.on("selection-complete", populateGrid2);
&amp;nbsp; //FeatureLayer2 selection
&amp;nbsp; FeatureLayer2.selectFeatures(querySBTest, FeatureLayer.SELECTION_NEW);


});
};&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:18:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/find-nearest-features-of-one-layer-to-another/m-p/455627#M42104</guid>
      <dc:creator>DavidChrest</dc:creator>
      <dc:date>2021-12-11T20:18:50Z</dc:date>
    </item>
  </channel>
</rss>

