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?

New contributor
user144508 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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


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


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


Your Answer

user144508 is a new contributor. Be nice, and check out our Code of Conduct.

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.