I have a shapefile of provinces (nxprovincias), and another shapefile of small, disconnected areas ("protected areas") that overlaps with the provinces. I want to easily calculate the total area of the protected areas within each province.

I am using QGIS 2.8.2 and all shapefiles are in the same CRS.

I have tried to "join attributes by location" - this gives an empty shapefile.

So because this didn't work, I then split the provinces shapefile up so that I have a different shapefile for each province. Then I used "clip" to clip the protected areas by province. This works perfectly for some provinces, and creates empty shapefiles for the others. Why would this happen?

Shapefiles used can be found here: https://www.dropbox.com/sh/thxvhkkoswyrldg/AAB5Lxh16uhj1WWOKVYtBj29a?dl=0

(In case anyone does try, the provinces that do not work are 4, 9, 11, 13 and 24, which all happen to be in the West of the country, for reasons unknown to me)

My question is: 1. Why does the clip only work sometimes? 2. Is there a better way to do this? I just want to know the area in each province, which seems like it should be easy to calculate?

  • Both of your layers have issue. Both contain multi-part polygons, and both contain geometry errors (self-intersecting polygons). While the multipart thing isn't a huge deal, the geometry errors are probably causing the problem. There's no need to split the provinces into separate files. Clip probably isn't what you want, and if it were you'd want to clip provinces by protected, not the other way around. An intersect should also get you what you want. You'll want to fix the geometry errors first (v.clean perhaps - see gis.stackexchange.com/questions/112687). – Chris W Jul 8 '15 at 23:34
  • Actually, I take that back. If you use intersect you get a bunch of polygons you then have to summarize. However if you clip the provinces with the protected areas, you have just those portions of the provinces and they're already at the 'minimum' number of polygons so no summary necessary. For what it's worth, I ran a clip in ArcGIS both before and after repairing the geometry and got the same result (an area for all provinces except one, which isn't overlapped by any protected area). QGIS may be choking on the geometry errors though, and those provinces might be where the error is. – Chris W Jul 8 '15 at 23:50
  • Thanks, I hadn't realised that my layers have errors and now I suppose it is because of how I created them. I have tried to use v.clean but it doesn't seem to have much effect. Specifically my issues are 1) I can't see any errors in the original provinces file? 2) Nothing I do with v.clean fixes the protected areas files. It seems like you managed to fix the errors - what did you do? And how do I avoid creating shapefiles full of errors for next time? – JackJ Jul 9 '15 at 2:17
  • I ran both Check Geometry and Repair Geometry in ArcGIS. With the protected areas there's only a single record, and it wouldn't let me explode/multi-to-singlepart it without repairing first, so there's no indication which shapes are the problem. For provinces, it supposedly only found errors with FID 20, which doesn't intersect protected at all. All errors were self-intersections. I'm not sure how you created the files, but those errors are likely introduced when the shapes were first created. You could try other repair methods in the question I linked. – Chris W Jul 9 '15 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.