def test__too_large_interp_dist__raises_runtimeerror(self): POLYGON = Polygon([[0, 0], [10, 0], [10, 10], [0, 10]]) with self.assertRaises(RuntimeError): Centerline(POLYGON, 10) centerline = Centerline(POLYGON, 5) self.assertIsInstance(centerline, Centerline)
def generate_centerlines(polygon_shps): ''' Create centerlines :param polygon_shps: input polygons :return: dictionary of linestrings ''' dct_centerlines = {} for i, geom in enumerate(polygon_shps): print(" now running Centerline creation") center_obj = Centerline(geom, 5) # 5 is the guessed smallest nodes distance, to avoid QhullError center_line_shply_line = center_obj.create_centerline() dct_centerlines[i] = center_line_shply_line return dct_centerlines
def generate_centerlines(polygon_shps): ''' Create centerlines :param polygon_shps: input polygons :return: dictionary of linestrings ''' dct_centerlines = {} for i, geom in enumerate(polygon_shps): print(" now running Centerline creation ", i) center_obj = Centerline(geom, 0.00019) # works for image-extracted rivers (cell res=0.0002), if larger than this it will give me QhullError center_line_shply_line = center_obj.create_centerline() dct_centerlines[i] = center_line_shply_line return dct_centerlines
def run(self): """ Starts processing the imported SHP file. It sedns the polygon's geometry allong with the interpolation distance to the Centerline class to create a Centerline object. The results (the polygon's ID and the geometry of the centerline) are added to the dictionary. """ for key in self.dct_polygons.keys(): poly_geom = self.dct_polygons[key] centerlineObj = Centerline(poly_geom, self.dist) self.dct_centerlines[key] = centerlineObj.createCenterline()
def generate_centerlines(polygon_shps): ''' Create centerlines :param polygon_shps: input polygons :return: dictionary of linestrings ''' dct_centerlines = {} for i, geom in enumerate(polygon_shps): print " now running Centerline creation" center_obj = Centerline(geom, 0.5) center_line_shply_line = center_obj.create_centerline() dct_centerlines[i] = center_line_shply_line return dct_centerlines
def test__polygon_with_interior_ring__returns_multilinestring(self): EXTERIOR = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] INTERIOR = [(1, 0), (0.5, 0.5), (1, 1), (1.5, 0.5), (1, 0)][::-1] POLYGON = Polygon(EXTERIOR, [INTERIOR]) centerline = Centerline(POLYGON) self.assertIsInstance(centerline, MultiLineString)
def test__object_has_assigned_attributes(self): POLYGON = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) ATTRIBUTES = {'id': 1, 'name': 'polygon', 'valid': True} centerline = Centerline(POLYGON, **ATTRIBUTES) self.assertEqual(centerline.id, ATTRIBUTES.get('id')) self.assertEqual(centerline.name, ATTRIBUTES.get('name')) self.assertEqual(centerline.valid, ATTRIBUTES.get('valid'))
def test__geometry_collection__raises_valueerror(self): GEOMETRY_COLLECTION = GeometryCollection( (Point(0, 0), LineString([(0, 0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)]), Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]))) with self.assertRaises(ValueError): Centerline(GEOMETRY_COLLECTION)
def test__multipolygon__raises_valueerror(self): POLYGONS = [Point(i, 0).buffer(0.1) for i in range(2)] MULTIPOLYGON = MultiPolygon(POLYGONS) with self.assertRaises(ValueError): Centerline(MULTIPOLYGON)
def setUpClass(cls): cls.POLYGON = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) cls.CENTERLINE = Centerline(cls.POLYGON)
def test__multilinestring__raises_valueerror(self): MULTILINESTRING = MultiLineString([((0, 0), (1, 1)), ((-1, 0), (1, 0))]) with self.assertRaises(ValueError): Centerline(MULTILINESTRING)
def test__linestring__raises_valueerror(self): LINESTRING = LineString([(0, 0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)]) with self.assertRaises(ValueError): Centerline(LINESTRING)
def test__multipoint__raises_valueerror(self): MULTIPOINT = MultiPoint([Point(0, 0), Point(1, 1)]) with self.assertRaises(ValueError): Centerline(MULTIPOINT)
def test__point__raises_valueerror(self): POINT = Point(0, 0) with self.assertRaises(ValueError): Centerline(POINT)
def setUpClass(cls): EXTERIOR = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] INTERIOR = [(1, 0), (0.5, 0.5), (1, 1), (1.5, 0.5), (1, 0)][::-1] cls.POLYGON = Polygon(EXTERIOR, [INTERIOR]) cls.CENTERLINE = Centerline(cls.POLYGON)
def test__polygon__returns_multilinestring(self): POLYGON = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) centerline = Centerline(POLYGON) self.assertIsInstance(centerline, MultiLineString)