def test_combine_dfs_osm(self):
     """test _combine_dfs_osm function within get_features_OSM function: """
     # define input parameters
     types = {'landuse=forest', 'waterway'}
     bbox = [47.2, 8.03, 47.3, 8.07]
     for item in types:
         print(item)
         result_NodesFromWays, result_NodesWaysFromRels = OSM._osm_api_query(
             item, bbox
         )  #strictly, this doesnt belong here, but needs to be invoked (tested before)
         globals()[str(item)+'_gdf_all_'+str(int(bbox[0]))+'_'+str(int(bbox[1]))] = \
         OSM._format_shape_osm(bbox, result_NodesFromWays, result_NodesWaysFromRels, item, DATA_DIR)
     # Execute function
     OSM_features_gdf_combined = \
         geopandas.GeoDataFrame(pd.DataFrame(columns=['Item', 'Name', 'Type', 'Natural_Type', 'geometry']),
              crs='epsg:4326', geometry='geometry')
     for item in types:
         print('adding results from %s ...' % item)
         OSM_features_gdf_combined = \
         OSM_features_gdf_combined.append(
             globals()[str(item)+'_gdf_all_'+str(int(bbox[0]))+'_'+str(int(bbox[1]))],
             ignore_index=True)
     i = 0
     for geom in OSM_features_gdf_combined.geometry:
         if geom.type == 'LineString':
             OSM_features_gdf_combined.geometry[i] = geom.buffer(0.000045)
         i += 1
     self.assertGreater(len(OSM_features_gdf_combined),
                        len(waterway_gdf_all_47_8))
     self.assertNotIn('LineString', OSM_features_gdf_combined.geometry.type)
 def test_osm_api_query(self):
     """test _osm_api_query within get_features_OSM function """
     bbox = [47.2, 8.03, 47.3, 8.07]
     item = 'landuse=forest'
     result_NodesFromWays, result_NodesWaysFromRels = OSM._osm_api_query(
         item, bbox)
     self.assertGreater(len(result_NodesFromWays.nodes), 0)
     self.assertGreater(len(result_NodesFromWays.ways), 0)
     self.assertGreater(len(result_NodesWaysFromRels.relations), 0)
    def test_format_shape_osm(self):
        """test _format_shape_osm function within get_features_OSM function: """
        #define input parameters
        bbox = [47.2, 8.03, 47.3, 8.07]
        item = 'landuse=forest'
        result_NodesFromWays, result_NodesWaysFromRels = OSM._osm_api_query(
            item, bbox)

        # Execute function to be tested
        globals()[str(item)+'_gdf_all_'+str(int(bbox[0]))+'_'+str(int(bbox[1]))] = \
        OSM._format_shape_osm(bbox, result_NodesFromWays, result_NodesWaysFromRels, item, DATA_DIR)
        # check that shapes were found both from relations and from way/nodes query
        self.assertGreater(
            len(globals()[str(item) + '_gdf_all_' + str(int(bbox[0])) + '_' +
                          str(int(bbox[1]))]),
            len(result_NodesWaysFromRels.relations))
        # check that geometry row exists and contains polygons / multipolygons
        self.assertEqual(
            globals()[str(item) + '_gdf_all_' + str(int(bbox[0])) + '_' +
                      str(int(bbox[1]))].iloc[0].geometry.type, 'Polygon')
        self.assertEqual(
            globals()[str(item) + '_gdf_all_' + str(int(bbox[0])) + '_' +
                      str(int(bbox[1]))].iloc[-1].geometry.type,
            'MultiPolygon')