An example app to show how to serialize and deserialize GEOS geometries using a common .proto file and plot them in flutter using pub.dev/packages/flutter_map.
The original inspiration of this serialization framework was made by topology-serialization-framework by 52North for Java Topology Suite
Since there's a port of Java Topology Suite for Dart, and the defacto of handling geodata in python is shapely, this example shows how to serialize and deserialize geometries transmitted from a python grpc server to a dart client.
- PostgreSQL database runing with postgis.net installed.
- Flutter
- Python
- Dart
- Python
- flutter_map - To renderer maps on app
- protobuf - Decode protobuf objects to dart objects from grpc payload
- grpc - Make calls to python grpc client and handle serialization of common objects like string, num, int, map etc
- freezed - Union classes to elegantly handle and render states of the app (Loading, Initial,Loaded, Error)
- provider - Handle state management
The backend architecture is just reading from a postgres(postgis) database using sqlalchemy and geoalchemy2(for geometric/postgis objects) and transmitting the read data to the app via grpc.
Packages used include
- grpcio==1.32.0
- grpcio-tools==1.32.0
- SQLAlchemy==1.3.20
- GeoAlchemy2==0.8.4
- protobuf==3.13.0
- psycopg2-binary==2.8.6
- Shapely==1.7.1
This example was run reading geometries from postgis, read using sqlalchemy with support for geometries using geoalchemy2 and serialized to geometries using shapely's to_shape
.
I added helpers to serialize the geometries into a grpc format compatible with the proto design below.
The geometries and metadata defined in the alaska.proto file were then transmitted through [grpc(grpc.net) to flutter and then deserialized into dart_jts geometries which is a port of the Java Topology Suite enabling us to do more spatial operations on the geometries from postgis.