I have a dataset of about 15000 events (protests) across the US with information about which state, county and city each event occurred in.

The problem is I also need to know which congressional district each event occurred in. Neither county or city on their own can reliably tell me about congr. district, but the dataset does however also contain coordinates (lat/long) for each event.

If I've understood things correctly I need to find shapefiles (?) for US congr. district (which I have found), extract some information from them about a geographic definition (?) of each district, which I can then load into R (the data software I'm using) and then use R to do the assigning.

I also understand that I need to make sure the coordinates in my dataset use the same coordinate system (coordinate reference system?) as the shapefiles (or something like that).

Have I understood the basics of what I need to do right? Is it a very complicated thing to do? Could anyone help me out or point me in the right direction?


2 Answers 2


Open processing toolbox with Ctrl+Alt+T, search for

  • Intersection


  • Join attributes by location

Both should give you the results you want. But if you can have points outside any district use Join attributes by location to also keep those points, Intersect will drop them

  • What do I need to do with my dataset file to make this work? The original file is an excel-file where latitude and longitude coordinates are two separate variables. Which one is the input file? Do I need to do something with my shapefile (.shp)? Nov 8, 2020 at 11:16

If you already are in R you can stay in R, with something like :


read_csv("my_points.csv") %>%              # if your original dataset is a CSV
  st_as_sf(coords = c("long", "lat")) %>%  # convert dataset to geographical object using the location variables
  st_join(read_sf("districts.shp"))        # open and join with the districts

And you'll get your original dataset augmented with the fields of the polygon in which each point is located (be sure that the projections are the same or add a st_transform() in between)

You can provide a dataset sample, so we could be more specific.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.