From 3a4094ca0760d29cfc284679b40ced1f97cabf94 Mon Sep 17 00:00:00 2001 From: Sune Broendum Woeller Date: Wed, 18 Mar 2015 11:01:30 +0100 Subject: [PATCH] ignore shapetype 0 (null shape) --- kartograph/layersource/shplayer.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kartograph/layersource/shplayer.py b/kartograph/layersource/shplayer.py index abd7dab..86db382 100644 --- a/kartograph/layersource/shplayer.py +++ b/kartograph/layersource/shplayer.py @@ -138,12 +138,17 @@ def get_features(self, attr=None, filter=None, bbox=None, ignore_holes=False, mi def shape2geometry(shp, ignore_holes=False, min_area=False, bbox=False, proj=None): if shp is None: return None + if shp.shapeType == 0: # null shape + return None if bbox and shp.shapeType != 1: - if proj: - left, top = proj(shp.bbox[0], shp.bbox[1], inverse=True) - right, btm = proj(shp.bbox[2], shp.bbox[3], inverse=True) - else: - left, top, right, btm = shp.bbox + try: + if proj: + left, top = proj(shp.bbox[0], shp.bbox[1], inverse=True) + right, btm = proj(shp.bbox[2], shp.bbox[3], inverse=True) + else: + left, top, right, btm = shp.bbox + except AttributeError: + return None sbbox = BBox(left=left, top=top, width=right - left, height=btm - top) if not bbox.intersects(sbbox): # ignore the shape if it's not within the bbox @@ -252,8 +257,8 @@ def shape2point(shp, proj=None): return MultiPoint(points) else: raise KartographError('shapefile import failed - no points found') - - + + def project_coords(pts, proj): for i in range(len(pts)): x, y = proj(pts[i][0], pts[i][1], inverse=True)