Get Congressional District output with location (lat, lon) input using REST call.

807
2
Jump to solution
05-26-2021 03:33 PM
MarkGlass
New Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

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

 

- Josh Carlson
Kendall County GIS
MarkGlass
New Contributor II

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=&parameterValues=&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"
}
}
]
}