Skip to content

Commit

Permalink
multipolygon fixes for issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
mxndrwgrdnr committed Aug 10, 2017
1 parent 5540058 commit 348752e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mander/districts.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import geopandas as gpd
import utils

class District(object):

class district(object):

def __init__(self, pathToGeojsonOrShapefile, epsg='2163'):
def __init__(self, pathToGeojsonOrShapefile, epsg='2163', **kwargs):
self.epsg = epsg
self.gdf = gpd.read_file(pathToGeojsonOrShapefile)
if not self.gdf.crs:
self.gdf.crs = {'init': 'epsg:4326'}
self.gdf = self.gdf.to_crs(epsg=self.epsg)
self.area = self.gdf.area.values[0]
self.perimeter = self.gdf.length.values[0]
self.x, self.y = self.gdf.geometry[0].exterior.coords.xy
self.coordPairs = zip(self.x, self.y)
self.coordPairs = utils.getCoordPairs(self.gdf)
14 changes: 14 additions & 0 deletions mander/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ def getMinBoundingCircleArea(district):
x, y, radius = mbc.make_circle(coords)
area = math.pi * radius**2
return area


def getCoordPairs(gdf):

coordPairs = []
if gdf.geom_type[0] == 'Polygon':
x, y = gdf.geometry[0].exterior.coords.xy
coordPairs = zip(x, y)
elif gdf.geom_type[0] == 'MultiPolygon':
for polygon in gdf.geometry[0]:
x, y = polygon.exterior.coords.xy
coordPairs += zip(x, y)
return coordPairs

0 comments on commit 348752e

Please sign in to comment.