0

I am trying to find the area of census tracts and counties and there are a handful that are not contiguous. I am using the python area library. Here is my code that works for all contiguous shapes.

        obj = {'type':'Polygon','coordinates': feature['geometry']['coordinates']}
        current_area = area(obj) / square_meter_to_square_mile

Here is an example of the coordinates:

{'type': 'Polygon', 'coordinates': [[[-79.891153, 40.497034, 0], [-79.890443, 40.494777, 0], [-79.889832, 40.491527, 0], [-79.884604, 40.490922, 0], [-79.884484, 40.488949, 0], [-79.884592, 40.487329, 0], [-79.888175, 40.48644, 0], [-79.8882, 40.483948, 0], [-79.883772, 40.483406, 0], [-79.879559, 40.483247, 0], [-79.876632, 40.483316, 0], [-79.874238, 40.48355, 0], [-79.865498, 40.485069, 0], [-79.865786, 40.491525, 0], [-79.865968, 40.495515, 0], [-79.862811, 40.49765, 0], [-79.859216, 40.497693, 0], [-79.859175, 40.496435, 0], [-79.856864, 40.498169, 0], [-79.851113, 40.493601, 0], [-79.850339, 40.49594, 0], [-79.84968, 40.497589, 0], [-79.848853, 40.503658, 0], [-79.849326, 40.506821, 0], [-79.849451, 40.507425, 0], [-79.850546, 40.514188, 0], [-79.850665, 40.51721, 0], [-79.850494, 40.520508, 0], [-79.851755, 40.520607, 0], [-79.85488, 40.520812, 0], [-79.85527, 
40.528789, 0], [-79.867579, 40.528512, 0], [-79.867259, 40.522247, 0], [-79.871734, 40.526388, 0], [-79.872237, 40.527164, 0], [-79.871867, 40.517058, 0], [-79.871676, 40.509746, 0], [-79.87278, 40.50971, 0], [-79.872672, 40.503888, 0], [-79.878623, 40.503694, 0], [-79.879079, 40.499454, 0], [-79.883633, 40.499245, 0], [-79.887353, 40.498669, 0], [-79.891153, 40.497034, 0]]]}

Here is what this looks like:

Tract in question

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
Matchinski
  • 65
  • 1
  • 1
  • 5
  • Does it not work already? What happened when you tried? If it did not work: can you think of a rule or process that lets you figure out which coordinates belong to which polygons? If you could split it up properly, could you think of a way to use that information to let you solve the problem? What exactly is the difficulty here? – Karl Knechtel Apr 08 '21 at 20:56
  • The `area` function doesn't like it. It says "key error coordinates". I don't know how to modify anything to make it account for any polygon with two parts. The picture renders fine, but I can't find the area of this. – Matchinski Apr 08 '21 at 21:00
  • 1
    A polygon with two parts is *just two polygons*. What happens when you try identifying those polygons, separately using the library to get the area of each, and adding up the results? – Karl Knechtel Apr 08 '21 at 21:05
  • I want to do that but I don't see how to tell where to split them. The only values repeated in that set are the first and last which doesn't make any sense to me. – Matchinski Apr 08 '21 at 21:09
  • I can't tell you what's going on with the error message without seeing [the complete error message](https://meta.stackoverflow.com/questions/359146/why-should-i-post-complete-errors-why-isnt-the-message-itself-enough). But after reading a bit about geojson, it seems like what you're trying to do with the code is take apart a bit of geojson data that should work fine already, to extract only the part that you find relevant. What happened when you tried just `area(feature)`? – Karl Knechtel Apr 08 '21 at 21:18
  • That should be a multipolygon otherwise the 2nd shell is considered to be a hole in the first one. – Ian Turton Apr 09 '21 at 08:19

1 Answers1

0

The error was not where I thought it was. That set of coords was all one shape and was no an issue. For the ones that were two shapes I had to loop through the list of sub-shapes and do each area separately.

Matchinski
  • 65
  • 1
  • 1
  • 5