Spatial Join

615
5
Jump to solution
04-24-2023 12:16 PM
TheGamer
Occasional Contributor

So, I have created a simple tool that converts an address into lat and long coordinates. I was wondering if there is an api which can use coordinates against a feature layer to see which polygon it belongs to using spatial join?

I basically want to map the coordinates to several hosted layers and get the polygon name which it maps to.

 

0 Kudos
1 Solution

Accepted Solutions
Sage_Wall
Esri Contributor

Hi @TheGamer ,

I'd suggest using the coordinates from your tool for the address to perform a spatial query on the feature layer.  More information on the Query class can be found here:

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html

There is also a convenient method to use to create a new query object from a feature layer documented here:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#createQu...

View solution in original post

5 Replies
Sage_Wall
Esri Contributor

Hi @TheGamer ,

I'd suggest using the coordinates from your tool for the address to perform a spatial query on the feature layer.  More information on the Query class can be found here:

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html

There is also a convenient method to use to create a new query object from a feature layer documented here:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#createQu...

TheGamer
Occasional Contributor

Hi, is there a way to check if the graphic contains the centroids of a feature layer?

0 Kudos
BlakeTerhune
MVP Regular Contributor

@TheGamer Yes, use the geometryEngine.

TheGamer
Occasional Contributor

Hi @BlakeTerhune I can't find the method, I want to get the ids of the feature layer whose centroids are in the graphic

0 Kudos
BlakeTerhune
MVP Regular Contributor

I think the contains method is what you would use. While looping over the features in the feature layer, test contains and then look at the attributes of the current feature and grab the id when you get a true.

0 Kudos