I'm developing an application which has a java backend servicing a REST API and a front end using Angular 8. I need to create a function that accepts lat, lon and returns the congressional district the point is located in.
Can anyone suggest how I might do that?
Thank you
Solved! Go to Solution.
Using, for example, the Census Bureau's service of legislative districts, all you need to do is include the lat/lon in the geometry parameter being sent in the REST query. Then specify geometryType=esriGeometryPoint and spatialRel=esriSpatialRelWithin.
I'm not sure how you're getting the lat/lon, maybe from a click or manual input, but once you have those values, just swap them into the geometry definition in the query:
geometry={"x" : lon, "y" : lat, "spatialReference" : {"wkid" : 4326}}
Using, for example, the Census Bureau's service of legislative districts, all you need to do is include the lat/lon in the geometry parameter being sent in the REST query. Then specify geometryType=esriGeometryPoint and spatialRel=esriSpatialRelWithin.
I'm not sure how you're getting the lat/lon, maybe from a click or manual input, but once you have those values, just swap them into the geometry definition in the query:
geometry={"x" : lon, "y" : lat, "spatialReference" : {"wkid" : 4326}}
In order to help someone with the same question here is a working example:
https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/Legislative/MapServer/0/query?where=1=1&text=&objectIds=&time=&geometry={"x" : -78.64541815397774, "y" : 35.88159837593537, "spatialReference" : {"wkid" : 4326}}&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelWithin&distance=&units=esriSRUnit_Foot&relationParam=&outFields=NAME&returnGeometry=false&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&havingClause=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&returnExtentOnly=false&datumTransformation=¶meterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=json
it returns:
{
"displayFieldName": "BASENAME",
"fieldAliases": {
"NAME": "NAME"
},
"fields": [
{
"name": "NAME",
"type": "esriFieldTypeString",
"alias": "NAME",
"length": 100
}
],
"features": [
{
"attributes": {
"NAME": "Congressional District 4"
}
}
]
}