示例#1
0
    def create_geodata_from_geodataframe(gdf, name):
        """Create map window using dataset list. Should be okay whether it is shapefile or geotiff

            Args:
                gdf (GeoDataFrame):  geopandas geodataframe object
                name (str): name of the gdf

            Returns:
                geodata (ipyleaflet.GeoData): ipyleaflet GeoData obejct

        """
        # create random color
        color = "#" + ''.join(
            [random.choice('0123456789ABCDEF') for j in range(6)])
        geodata = ipylft.GeoData(geo_dataframe=gdf,
                                 style={
                                     'color': 'black',
                                     'fillColor': color,
                                     'opacity': 0.05,
                                     'weight': 1.9,
                                     'dashArray': '2',
                                     'fillOpacity': 0.6
                                 },
                                 hover_style={
                                     'fillColor': 'red',
                                     'fillOpacity': 0.2
                                 },
                                 name=name)

        return geodata
示例#2
0
    def get_gdf_map(datasets: list):
        """Get ipyleaflet map with list of datasets with geopandas .

        Args:
            datasets (list): a list of pyincore Dataset objects

        Returns:
            ipyleaflet.Map: ipyleaflet Map object

        """

        # TODO: how to add a style for each dataset
        # TODO: performance issue. If there are a lot of data, the browser will crash
        geo_data_list = []
        # (min_lat, min_lon, max_lat, max_lon)
        bbox_all = [9999, 9999, -9999, -9999]

        for dataset in datasets:
            # maybe this part should be moved to Dataset Class
            gdf = gpd.read_file(dataset.local_file_path)
            geo_data = ipylft.GeoData(geo_dataframe=gdf,
                                      name=dataset.metadata['title'])
            geo_data_list.append(geo_data)

            bbox = gdf.total_bounds
            bbox_all = GeoUtil.merge_bbox(bbox_all, bbox)

        m = GeoUtil.get_ipyleaflet_map(bbox_all)

        for entry in geo_data_list:
            m.add_layer(entry)

        m.add_control(ipylft.LayersControl())
        return m
示例#3
0
 def shapefile_buttom(self, *args):
     if self.control_selectDownload.value == 'Watershed':
         try:
             self.shape = gpd.read_file(self.control_shapefileText.value)
             self.geo_data = ipyleaflet.GeoData(geo_dataframe=self.shape,
                                                name='Bacias',
                                                style={
                                                    'color': 'red',
                                                    'fillColor': '#c51b8a',
                                                    'opacity': 0.05,
                                                    'weight': 1.9,
                                                    'dashArray': '2',
                                                    'fillOpacity': 0.6
                                                },
                                                hover_style={
                                                    'fillColor': 'red',
                                                    'fillOpacity': 0.2
                                                })
             self.m01.add_layer(self.geo_data)
         except:
             pass
     else:
         try:
             # self.m01.remove_layer(geo_data)
             pass
         except:
             pass
示例#4
0
    def plot_network_dataset(network_dataset: NetworkDataset):
        """Creates map window with Network Dataset visualized

        Args:
            network_dataset (NetworkDataset):  pyincore Network Dataset object

        Returns:
            m (ipyleaflet.Map): ipyleaflet Map object

        """
        # get node file name path
        link_path = network_dataset.link.file_path
        link_file_name = os.path.basename(link_path)

        # get node file name path
        node_path = network_dataset.node.file_path
        node_file_name = os.path.basename(node_path)

        # read file using geopandas
        node_gdf = gpd.read_file(node_path)
        link_gdf = gpd.read_file(link_path)

        geo_data_list = []
        # (min_lat, min_lon, max_lat, max_lon)
        bbox_all = [9999, 9999, -9999, -9999]

        # add node data to list
        node_geo_data = ipylft.GeoData(geo_dataframe=node_gdf,
                                       name=node_file_name)
        geo_data_list.append(node_geo_data)

        # add link data to list
        link_geo_data = ipylft.GeoData(geo_dataframe=link_gdf,
                                       name=link_file_name)
        geo_data_list.append(link_geo_data)

        bbox = link_gdf.total_bounds
        bbox_all = GeoUtil.merge_bbox(bbox_all, bbox)

        m = GeoUtil.get_ipyleaflet_map(bbox_all)

        for entry in geo_data_list:
            m.add_layer(entry)

        m.add_control(ipylft.LayersControl())

        return m
    def get_layer(shapes: gpd.GeoDataFrame, color):
        def get_info_text():
            return '<h4>{}</h4>'.format(nuts_ids_column) + '<br>'.join([
                str(shapes[col].values[0])
                for col in info_columns if col in shapes.columns
            ])

        def hover_event_handler(**kwargs):
            info_widget_html.value = get_info_text()
            out = interactive_output(
                _plot_time_hist_values,
                dict(data=fixed(relevant_data),
                     timestamp_column=fixed('_timestamp'),
                     value_column=fixed(color_column),
                     xlims=fixed(date_limits)))
            time_hist.children = [out]

        def click_event_handler(**kwargs):
            if kwargs['event'] != 'click':
                return
            if tweets_table.placeholder == nuts_id:
                tweets_table.placeholder, tweets_table.value = '', ''
            elif len(relevant_data) > 0:
                header = '<b>{} {}</b>'.format(nuts_ids_column, nuts_id)
                tweets_data = relevant_data[[
                    c for c in table_columns if c in relevant_data.columns
                ]].sort_values(table_columns[0]).dropna(axis='columns',
                                                        how='all')
                tweets_table.value = header + tweets_data.to_html(na_rep='',
                                                                  index=False)
                tweets_table.layout.margin = '5px'
                tweets_table.placeholder = nuts_id

        nuts_id = shapes[nuts_ids_column].values[0]
        style = {
            'color': color,
            'fillColor': color,
            'opacity': 0.5,
            'weight': 1.9,
            'dashArray': '2',
            'fillOpacity': 0.2
        }
        hover_style = {'fillColor': color, 'fillOpacity': 0.5, 'weight': 5}
        layer = ipyleaflet.GeoData(geo_dataframe=shapes,
                                   style=style,
                                   hover_style=hover_style)
        if full_data is None or tweets_table is None or time_hist is None:
            return layer
        relevant_data = _date_filter(
            full_data[full_data[nuts_ids_column].str.startswith(nuts_id,
                                                                na=False)],
            date_limits).reset_index()
        if time_hist is not None and info_widget_html is not None:
            layer.on_hover(hover_event_handler)
        if tweets_table is not None:
            layer.on_click(click_event_handler)
        return layer
示例#6
0
    def get_gdf_wms_map(datasets,
                        wms_datasets,
                        wms_url=globals.INCORE_GEOSERVER_WMS_URL):
        """Get a map with WMS layers from list of datasets for geopandas and list of datasets for WMS

        Args:
            datasets (list): list of pyincore Dataset objects
            wms_datasets (list): list of pyincore Dataset objects for wms layers
            wms_url (str): URL of WMS server

        Returns:
            obj: A ipylfealet Map object

        """

        # TODO: how to add a style for each WMS layers (pre-defined styules on WMS server) and gdf layers

        # (min_lat, min_lon, max_lat, max_lon)
        bbox_all = [9999, 9999, -9999, -9999]

        geo_data_list = []
        for dataset in datasets:
            # maybe this part should be moved to Dataset Class
            gdf = gpd.read_file(dataset.local_file_path)
            geo_data = ipylft.GeoData(geo_dataframe=gdf,
                                      name=dataset.metadata['title'])
            geo_data_list.append(geo_data)

            bbox = gdf.total_bounds
            bbox_all = GeoUtil.merge_bbox(bbox_all, bbox)

        wms_layers = []
        for dataset in wms_datasets:
            wms_layer_name = 'incore:' + dataset.id
            wms_layer = ipylft.WMSLayer(url=wms_url,
                                        layers=wms_layer_name,
                                        format='image/png',
                                        transparent=True,
                                        name=dataset.metadata['title'] +
                                        '-WMS')
            wms_layers.append(wms_layer)

            bbox = dataset.metadata['boundingBox']
            bbox_all = GeoUtil.merge_bbox(bbox_all, bbox)

        m = GeoUtil.get_ipyleaflet_map(bbox_all)

        for layer in wms_layers:
            m.add_layer(layer)

        for g in geo_data_list:
            m.add_layer(g)

        m.add_control(ipylft.LayersControl())

        return m
示例#7
0
    def add_gdf(self, in_gdf, style=None, layer_name="Untitled"):
        """Adds a Pandas DataFrame to the map

        Args:
            in_gdf (gpd.GeoDataFrame): The GeoPandas GeoDataFrame.
            style (dict, optional): The style for the GeoDataFrame. Defaults to None.
            layer_name (str, optional): The layer name for the GeoDataFrame layer. Defaults to "Untitled".
        """
        geodata = ipyleaflet.GeoData(geo_dataframe=in_gdf, name=layer_name)
        self.add_layer(geodata)