Skip to content

An example app to show how to transmit GEOS geometries over gRPC and render them in flutter using flutter_map.

Notifications You must be signed in to change notification settings

bettdouglas/flutter_python_grpc

Repository files navigation

flutter_python_grpc

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.

GeoProtobuf proto spec

Requirements

  • PostgreSQL database runing with postgis.net installed.
  • Flutter
  • Python

Languages Used

  • Dart
  • Python

Frameworks Used

Mobile App

  1. flutter_map - To renderer maps on app
  2. protobuf - Decode protobuf objects to dart objects from grpc payload
  3. grpc - Make calls to python grpc client and handle serialization of common objects like string, num, int, map etc
  4. freezed - Union classes to elegantly handle and render states of the app (Loading, Initial,Loaded, Error)
  5. provider - Handle state management

Backend(API)

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

  1. grpcio==1.32.0
  2. grpcio-tools==1.32.0
  3. SQLAlchemy==1.3.20
  4. GeoAlchemy2==0.8.4
  5. protobuf==3.13.0
  6. psycopg2-binary==2.8.6
  7. 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.

Alaska Service Spec

About

An example app to show how to transmit GEOS geometries over gRPC and render them in flutter using flutter_map.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published