Project

General

Profile

Live » History » Version 6

Philippe May, 06/05/2019 17:24

1 1 Philippe May
h1. Live
2 1 Philippe May
3 1 Philippe May
While the primary intention is use a database for all layers, Gisaf has the capability to display layers directly from GeoPandas GeodataFrames.
4 1 Philippe May
5 1 Philippe May
In this case, they can also be updated dynamically, adding animation capabilities to the maps.
6 1 Philippe May
7 1 Philippe May
This can be used for, eg:
8 1 Philippe May
9 1 Philippe May
* displaying text (eg. temperatures, well levels)
10 1 Philippe May
* moving elements
11 1 Philippe May
* results of computations and analysis...
12 1 Philippe May
13 1 Philippe May
h2. Using live directly from a Python script on the Gisaf server
14 1 Philippe May
15 1 Philippe May
Eg:
16 1 Philippe May
17 1 Philippe May
<pre><code class="python">
18 1 Philippe May
#!/usr/bin/env python
19 1 Philippe May
from asyncio import run
20 1 Philippe May
21 1 Philippe May
import geopandas as gpd
22 1 Philippe May
23 1 Philippe May
from shapely.geometry import Point
24 1 Philippe May
25 1 Philippe May
from gisaf.live import live_server
26 1 Philippe May
27 1 Philippe May
async def run(gs):
28 1 Philippe May
    gdf = gpd.GeoDataFrame(
29 1 Philippe May
        data={
30 1 Philippe May
            'geometry': [
31 1 Philippe May
                Point(12.01, 79.81)
32 1 Philippe May
            ]
33 1 Philippe May
        },
34 1 Philippe May
        crs='epsg:4326'
35 1 Philippe May
    )
36 1 Philippe May
37 1 Philippe May
    await live_server.publish_gdf('FooLayer', gdf)
38 1 Philippe May
39 1 Philippe May
40 1 Philippe May
async def main():
41 1 Philippe May
    await live_server.create_connections()
42 1 Philippe May
    await run(gs)
43 1 Philippe May
44 1 Philippe May
if __name__ == '__main__':
45 1 Philippe May
    run(main())
46 1 Philippe May
</code></pre>
47 2 Philippe May
48 2 Philippe May
Explanations:
49 2 Philippe May
50 2 Philippe May
1. Initialize the connection with @live_server.create_connections()@.
51 2 Philippe May
52 2 Philippe May
2. Publish a geo dataframe with @live_server.publish_gdf('name of the layer', gdf)@
53 2 Philippe May
54 2 Philippe May
h2. From Jupyter notebooks
55 1 Philippe May
56 6 Philippe May
Quite similarly to the case above, jupyter notebooks (running on a different machine) can be used to publish and control live layers through an HTTP POST API (at http:///api/live/my_channel_name), which is multipart (the layer definition in the first part, the data in the second).
57 6 Philippe May
58 6 Philippe May
<pre>
59 6 Philippe May
from gisaf.ipynb_tools import Gisaf
60 6 Philippe May
gs = Gisaf()
61 6 Philippe May
async_run(gs.to_live_layer(my_channel_name, my_gdf))
62 6 Philippe May
</pre>
63 6 Philippe May
64 6 Philippe May
See the examples in @Templates/gisaf_live_templates@ of the avgs jupyter notebooks.
65 2 Philippe May
66 2 Philippe May
h2. Architecture
67 2 Philippe May
68 2 Philippe May
Gisaf live layers use a redis data store for:
69 2 Philippe May
70 2 Philippe May
1. Storage of the live layers
71 2 Philippe May
72 2 Philippe May
2. Publish/subscribe for live updates.
73 2 Philippe May
74 2 Philippe May
The live updates are sent through a websocket, initiated by the clients (web browsers).
75 2 Philippe May
76 1 Philippe May
Moreover, Gisaf exposes an HTTP API for external control of the live layers, eg. by Jupyter notebooks running on another server.
77 3 Philippe May
78 5 Philippe May
p=. !Live_arch.png!