I have one shapefile that is railroad lines (in red) and another that is a shapefile of US county boundaries in 1890 and I would like to figure out which counties have railroads versus counties that do not (so the intersection between the two layers) to be able to create an 0-1 indicator for a county having a railroad or not and I have not been able to figure out how to do this in QGIS.

I am at a very novice level.

2 Answers 2

  1. Open the attribute table of your county layer
  2. Field calculate a new field (Whole Number (int) type) with the expression: overlay_intersects( layer:='railroads'), replace railroads, with the name of your railroad layer. It will return True when there's a railroad intersecting the polygon, else False. This will be saved as 1 or 0 in the integer field: enter image description here

You could manually create the attribute in the polygon layer in the attribute layer

enter image description here

Then use select by location tool. Use polygon layer to be selected, using the "intersect" predicate and compare with line layer.

enter image description here

Then open the polygon attribute table, select the layer you want to change, type the value you want to put and press to refresh selected only.

enter image description here

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.