コード例 #1
0
    def catch_del(self):
        """
        Catchment delineation function using the REC rivers and catchment GIS layers.

        Returns
        -------
        GeoDataFrame of Catchments.
        """
        if hasattr(self, 'catch_gdf_all'):
            catch_gdf =  self.catch_gdf_all[self.catch_gdf_all.ExtSiteID.isin(self.input_summ.ExtSiteID)].copy()
        else:

            ## Read in GIS data
            if not hasattr(self, 'rec_rivers'):
                self.load_rec()

            ## Catch del
            catch_gdf = rec.catch_delineate(self.flow_sites_gdf, self.rec_rivers, self.rec_catch)

        ## Save if required
        if hasattr(self, 'output_path'):
            run_time = pd.Timestamp.today().strftime('%Y-%m-%dT%H%M')
            catch_del_shp = param['output']['catch_del_shp'].format(run_date=run_time)
            catch_gdf.to_file(os.path.join(self.output_path, catch_del_shp))

        ## Return
        setattr(self, 'catch_gdf', catch_gdf)
        return catch_gdf
コード例 #2
0
ファイル: test_rec.py プロジェクト: mullenkamp/gistools
def test_catch_delineate():
    poly1 = rec.catch_delineate(sites=sites_shp_path,
                                rec_streams=rec_streams_shp_path,
                                rec_catch=rec_catch_shp_path,
                                stream_order_col='ORDER',
                                segment_id_col='NZREACH',
                                from_node_col='NZFNODE',
                                to_node_col='NZTNODE')

    assert (round(poly1.area[0]) > 420000000) & (round(poly1.area[1]) >
                                                 520000000)
コード例 #3
0
    try:
        catch_del_shp = [
            p for p in os.listdir(results_path)
            if (catch_del_base in p) and ('.shp' in p)
        ][-1]
        catch_gdf = gpd.read_file(os.path.join(results_path, catch_del_shp))
    except:
        sql1 = sql_arg()

        rec_rivers_dict = sql1.get_dict(rec_rivers_sql)
        rec_catch_dict = sql1.get_dict(rec_catch_sql)

        rec_rivers = mssql.rd_sql(**rec_rivers_dict)
        rec_catch = mssql.rd_sql(**rec_catch_dict)

        catch_gdf = rec.catch_delineate(flow_sites_gdf, rec_rivers, rec_catch)
        catch_gdf.to_file(os.path.join(results_path, catch_del_shp))

    ###################################
    ### WAP selection

    wap1 = mssql.rd_sql(permit_server,
                        permit_database,
                        crc_wap_table, ['ExtSiteID'],
                        where_in={
                            'ConsentStatus': param['crc_status']
                        }).ExtSiteID.unique()

    sites3 = sites1[sites1.ExtSiteID.isin(wap1)].copy()
    sites3.rename(columns={'ExtSiteID': 'Wap'}, inplace=True)
sites_shp = 'flow_recorders_pareora.shp'
rec_streams_shp = 'rec_streams_pareora.shp'
rec_catch_shp = 'rec_catch_pareora.shp'
catch_shp = 'catchment_pareora.shp'

sites_shp_path = os.path.join(base_path, shp_dir, sites_shp)
rec_streams_shp_path = os.path.join(base_path, shp_dir, rec_streams_shp)
rec_catch_shp_path = os.path.join(base_path, shp_dir, rec_catch_shp)
catch_shp_path = os.path.join(base_path, shp_dir, catch_shp)

sites_col_name = 'SITENUMBER'
poly_col_name = 'Catchmen_1'
line_site_col = 'NZREACH'

export_shp = 'pareora_catchments.shp'

#######################################
### Catchment delineation

pts = util.load_geo_data(sites_shp_path)
pts['geometry'] = pts.geometry.simplify(1)

poly1 = rec.catch_delineate(sites_shp_path,
                            rec_streams_shp_path,
                            rec_catch_shp_path,
                            sites_col=sites_col_name,
                            buffer_dis=400)

poly1.to_file(os.path.join(base_path, shp_dir, export_shp))
コード例 #5
0
sites1 = mssql.rd_sql(server, database, sites_table,
                      ['ExtSiteID', 'NZTMX', 'NZTMY'])

sites0 = sites1[sites1.ExtSiteID == site].copy()

sites2 = vector.xy_to_gpd('ExtSiteID', 'NZTMX', 'NZTMY', sites0)

sql1 = sql_arg()

rec_rivers_dict = sql1.get_dict(rec_rivers_sql)
rec_catch_dict = sql1.get_dict(rec_catch_sql)

###################################
### Catchment delineation and WAPs

catch1 = rec.catch_delineate(sites2, rec_rivers_dict, rec_catch_dict)
catch1.to_file(os.path.join(results_path, catch_del_shp))

wap1 = mssql.rd_sql(server, database, crc_wap_table, ['wap']).wap.unique()

sites3 = sites1[sites1.ExtSiteID.isin(wap1)].copy()

sites4 = vector.xy_to_gpd('ExtSiteID', 'NZTMX', 'NZTMY', sites3)

sites5 = vector.sel_sites_poly(sites4, catch1)
sites5.to_file(os.path.join(results_path, wap_shp))

##################################
### Get crc data

allo1 = AlloUsage(crc_wap_filter={'wap': sites5.ExtSiteID.tolist()},
コード例 #6
0
def test_catch_delineate():
    poly1 = rec.catch_delineate(sites_shp_path, rec_streams_shp_path, rec_catch_shp_path)

    assert (round(poly1.area[0]) == 422889430) &(round(poly1.area[1]) == 528523857)