Live » History » Version 10
Philippe May, 06/05/2019 17:30
| 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 | 8 | Philippe May | |
| 55 | 9 | Philippe May | This mode of operation is well adapted for live updates, when the script can be controlled by @systemd@ or similar OS service control tool. |
| 56 | 8 | Philippe May | |
| 57 | 2 | Philippe May | h2. From Jupyter notebooks |
| 58 | 1 | Philippe May | |
| 59 | 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). |
| 60 | 6 | Philippe May | |
| 61 | 6 | Philippe May | <pre> |
| 62 | 6 | Philippe May | from gisaf.ipynb_tools import Gisaf |
| 63 | 6 | Philippe May | gs = Gisaf() |
| 64 | 6 | Philippe May | async_run(gs.to_live_layer(my_channel_name, my_gdf)) |
| 65 | 6 | Philippe May | </pre> |
| 66 | 6 | Philippe May | |
| 67 | 7 | Philippe May | In other words, from the example above using directly Gisaf code, the only difference is the replacement of @await live_server.publish_gdf(...@ by @async_run(gs.to_live_layer(...@. |
| 68 | 7 | Philippe May | |
| 69 | 6 | Philippe May | See the examples in @Templates/gisaf_live_templates@ of the avgs jupyter notebooks. |
| 70 | 2 | Philippe May | |
| 71 | 2 | Philippe May | h2. Architecture |
| 72 | 2 | Philippe May | |
| 73 | 2 | Philippe May | Gisaf live layers use a redis data store for: |
| 74 | 2 | Philippe May | |
| 75 | 2 | Philippe May | 1. Storage of the live layers |
| 76 | 2 | Philippe May | |
| 77 | 2 | Philippe May | 2. Publish/subscribe for live updates. |
| 78 | 2 | Philippe May | |
| 79 | 2 | Philippe May | The live updates are sent through a websocket, initiated by the clients (web browsers). |
| 80 | 2 | Philippe May | |
| 81 | 1 | Philippe May | Moreover, Gisaf exposes an HTTP API for external control of the live layers, eg. by Jupyter notebooks running on another server. |
| 82 | 3 | Philippe May | |
| 83 | 10 | Philippe May | This mode of operation is well adapted for experimenting with GeoPandas and publishing the results directly in the context, with other layers coming from the database. |
| 84 | 10 | Philippe May | |
| 85 | 5 | Philippe May | p=. !Live_arch.png! |