-1

I have a bunch of addresses that I need to find the corresponding State Senate and State House district for their latitude and longitude.

It is possible to use shapefiles in QGIS to get this information manually, but is there a way to do this programatically?

0

It's possible that some government entity might be hosting your states districts as a web API service already in which case you may find it easier to programmatically identify these values using HTTPS requests since many scripting languages work well as HTTP clients.

For example, here as service hosted by the state of Wisconsin that I could use in a Python script that

https://mapservices.legis.wisconsin.gov/arcgis/rest/services/Statewide/FML_ASC/MapServer/1/query?where=&text=&objectIds=&time=&geometry={"x":-10199977.398571232,"y":5334390.01402165,"spatialReference":{"wkid":102100,"latestWkid":3857}}&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=false&f=json

I could query a list of points using Python like so:

import requests
import json

locations = [
  [-10410111.756214993, 5596413.462928988],
  [-10310111.756214993, 5696413.462928988]
]
for location in locations:
  url = "https%3A%2F%2Fmapservices.legis.wisconsin.gov%2Farcgis%2Frest%2Fservices%2FStatewide%2FFML_ASC%2FMapServer%2F1%2Fquery%3Fwhere%3D%26text%3D%26objectIds%3D%26time%3D%26geometry%3D%7B%22x%22%3A" + str(location[0]) + "%2C%22y%22%3A" + str(location[1]) + "%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%26geometryType%3DesriGeometryPoint%26inSR%3D%26spatialRel%3DesriSpatialRelIntersects%26relationParam%3D%26outFields%3D*%26returnGeometry%3Dtrue%26f%3Dpjson%0A"

    response = requests.get(url)

    responseobj = json.loads(response.text)
    district = responseobj["response"]["SEN_NUM"]

    print str(location[0]) + "," str(location[1]) + " senate district: " + str(district)

Here is another example of a similar service that is pulished as an ArcGIS REST API that is hosted to support apps maintained by www.house.gov

https://services1.arcgis.com/o90r8yeUBWgKSezU/arcgis/rest/services

It contains congressional districts and exposes a REST API that supports point intersection like so:

https://services1.arcgis.com/o90r8yeUBWgKSezU/ArcGIS/rest/services/Congressional_Districts/FeatureServer/0/query?f=json&returnGeometry=false&spatialRel=esriSpatialRelIntersects&geometry={"x":-10410111.756214993,"y":5596413.462928988,"spatialReference":{"wkid":102100,"latestWkid":3857}}&geometryType=esriGeometryPoint&inSR=102100&outFields=*

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.