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:
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.