3

I'm trying to calculate the area of US congressional districts (shapefiles from here). I have eight different district shapefiles. I can calculate areas perfectly for the first five shapefiles (corresponding to the 81st, 87th, 92nd, 93rd, and 98th Congresses).

But for the 103rd, 108th, and 113th Congress shapefiles, it screws up. When I calculate areas manually (Vector->Geometry Tools->Export/Add Geometry Columns), the progress bar stalls at some point (eg. 53% for districts113). When I calculate areas using python, (processing.runalg('qgis:exportaddgeometrycolumns',layer,0,output)), I can see the progress bar slowly get up to 53%, then it finishes suddenly, and the resulting shapefile is missing half the states.

What's the problem here?

  • 1
    It sounds like you have a bad geometry at 53% of your features. Have a read of gis.stackexchange.com/questions/112687/… and see if that helps. You are right, relative sizes can be in any units so dd should be fine although you could get different results if the data is projected and the polygons are roughly the same size. It would be interesting to see if you get different results if the data is projected to something like EPSG:102003 (USA contiguous Albers equal area conic) which should be fine for all of continental U.S. – Michael Stimson Sep 7 '17 at 20:54
  • Which of the solutions in that link do you recommend? Creating a buffer doesn't work (I get the same stalling behavior). I'll need to install GRASS to use vclean, and I'll need to learn how to configure the processing provider to use lwgeom. – Macaulay Sep 8 '17 at 15:05
  • Try this one docs.qgis.org/2.14/en/docs/user_manual/plugins/… From Esri it reports FID 0 to 40 have self intersections (hourglass/bow-tie) which seems to be the main problem, so perhaps concentrate on that. I cannot endorse any method in QGIS, I haven't tried any because the Esri 'repair geometry' is so easy/handy/thorough and I have access to it. Because of the geometry errors any geometry tool is likely to have a hard time, this includes buffer/overlay operations; Bad geometries occur frequently in shapefiles, especially those derived from CAD or GPS. – Michael Stimson Sep 10 '17 at 20:56
  • Thanks for your help! I went ahead using the census shapefiles for districts >= 103, but I'll give that a try if I run into any more issues. – Macaulay Sep 11 '17 at 22:43
3

You have definitely got some bad geometries in there.. I downloaded the file and used Esri 'repair geometry' (for convenience, the QGIS method takes longer):

WARNING 000986: D:\Tmp\arcDEBB\districts1130.txt contains the full list of non simple features.
WARNING 000461: Repaired feature 0 because of self intersections
WARNING 000461: Repaired feature 0 because of self intersections
WARNING 000461: Repaired feature 1 because of self intersections
.
. many similar rows removed
.
WARNING 000461: Repaired feature 37 because of self intersections
WARNING 000461: Repaired feature 39 because of self intersections
WARNING 000461: Repaired feature 39 because of self intersections
WARNING 000461: Repaired feature 40 because of self intersections
Succeeded at Fri Sep 08 07:03:16 2017 (Elapsed Time: 5 minutes 29 seconds)

Then I added two fields 'ShapeArea', 'AlbersArea' and calculated the geometry for both native (geographic into ShapeArea) and projected (Albers Equal area EPSG:102003 into AlbersArea). The result is here (I don't usually do this and please virus check the zip before you open just in case ..)

1

From the link that you give us:

District geographic definitions are encoded in US Census standard unprojected format using the NAD83 coordinate datum (PostGIS SRID 4269). The PROJ.4 string is:

+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs

Units of this CRS are degrees, the area can't be calculated from degrees. You need to reproject to a feet or meter projection (such UTM).

  • I just need relative areas (district areas relative to county areas). Does it matter it's calculated in degrees? Also, how does that address why I can calculate areas for districts 81-98, but not for districts 103-113? – Macaulay Sep 7 '17 at 20:30
  • 1
    @Macaulay a relative area is the comparison of two absolute areas, hence you need to calculate each area prior to make comparisons – aldo_tapia Sep 7 '17 at 20:50
  • I have an area column for districts81, so QGIS is capable of calculating areas in degrees. – Macaulay Sep 8 '17 at 0:03
  • @Macaulay and units have sense? – aldo_tapia Sep 8 '17 at 0:16
  • Relative area is unit-free. – Macaulay Sep 8 '17 at 0:32

Your Answer

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.