TransWikia.com

Using QGIS to sort datapoints into districts

Geographic Information Systems Asked by Gustaf Westin on June 21, 2021

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

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

  • Intersection

or:

  • 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

Answered by BERA on June 21, 2021

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

library(sf)
library(dplyr)
library(readr)


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.

Answered by mdag02 on June 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP