Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdesbas committed Jun 12, 2021
2 parents f33ec03 + b38ad95 commit ebc273e
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 293 deletions.
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Enjoy !
python vectipy.py run -p 5000
```

![Screenshort running vectipy](screenshot1.png "Running Vectipy")
![Screenshort running vectipy](assets/graphics/screenshot1.png "Running Vectipy")

Use following routes
- http://localhost:5000/ Show availables layers
Expand All @@ -51,20 +51,49 @@ Use following routes
- http://localhost:5000/map/MY_LAYER Layer preview
- http://localhost:5000/map/MY_LAYER.geojson GeoJson file (for download or webmap)

For layers not in public schema, use _SCHEMA.MY_LAYER_.

Tips
- Add a geometry index on each layer greatly improve performances (`CREATE INDEX my_layer_geom_3857_idx ON my_layer USING GIST (ST_Transform(geom, 3857))` );
Notes
- Add a **geometry index** on each layer greatly improve performances (`CREATE INDEX my_layer_geom_3857_idx ON my_layer USING GIST (ST_Transform(geom, 3857))` );
- Preview only avaible for constrained geometry type (see https://postgis.net/docs/using_postgis_dbmanagement.html#Manual_Register_Spatial_Column )
- Install [gunicorn](https://gunicorn.org/) (`pip install gunicorn`) and use `gunicorn vectipy:app` for production


## Configuration

Tables with a geometric column are automatically serverd by Vectipy. I suggest to disable this in _config.toml_ and explicitly configure layers that you want to serve.

### Layers definition

You can define _Layers_ or _Collections_ (multi-layers tiles)


```toml
[[collection]] #a multi-layers tileset
name = "my_multilayers_tiles" #the collection name, used in tiles url
[[collection.layer]]
name = "first_layer" #layer name (published name, used for style definition)
table_name = "table1" #database table name
minzoom = 14 #OPTIONAL
maxzoom = 20 #OPTIONAL
columns = [ "id", "label"] #OPTIONAL published columns (default : all columns)
geometry_column = "geom" #geometry column (default : geom)

[[collection.layer]]
name = "second_layer"
table_name = "table2"

[[layers]] #a single-layer tileset
table_name = "my_single_layer"
name = "my_table"
```

## Features :
- [x] Easy to deploy MVT (pbf) server
- [x] TileJson metadata
- [x] Frontend preview with [MapLibre GL](https://github.com/maplibre/maplibre-gl-js)
- [x] Serve GeoJson file
- [ ] Multi-layer tiles support
- [ ] Support MVT Feature ID
- [x] Serve GeoJSON file
- [ ] Cache system
- [ ] OGC API Features (WFS 3) server https://www.ogc.org/standards/ogcapi-features



Expand Down
52 changes: 42 additions & 10 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
from flask import Flask, render_template

import os
import toml
import toml, json
import psycopg2.extras

from .mvtserver import Pg2mvt
from .mvtserver import scandb, Layer, LayerCollection

def page_not_found(e):
return render_template('404.html'), 404

def create_app():
app = Flask(__name__)
app.secret_key = os.environ.get('SECRET_KEY','testingSssecretKey')
try:
with open('app/motd.txt','r') as f:
print(f.read())
except FileNotFoundError:
pass

default_config={
'TILES':{
'MAX_FEATURES': 2000,
'SRID' : 4326,
'EXTENT' : 4096,
'BUFFER' : 256
},
'DEFAULT_SCHEMA':'public'
'SERVER':{
'DEFAULT_SCHEMA':'public',
'AUTO_PUBLISH_LAYERS':False
}

}
app.config.update(default_config)
with open('config.toml', 'r') as f:
Expand All @@ -33,15 +42,38 @@ def create_app():
'cursor_factory': psycopg2.extras.RealDictCursor
}
app.config['DEFAULT_SCHEMA'] = 'public'
app.pg2mvt = Pg2mvt(app.config['DB'] )

from app.routes import geo
app.register_blueprint(geo)
app.register_error_handler(404, page_not_found)
app.config['layers'] = app.pg2mvt.scandb()

app.config['data'] = dict()
if app.config['SERVER']['AUTO_PUBLISH_LAYERS']:
print('Table with geom are automatically published')
for l in scandb(dbparam=app.config['DB'])['layer']:
app.config['data'][l['name']] = Layer(layer_name=l['name'], table_name=l['name'], dbparam=app.config['DB'], geometry_column = l['geom'], columns=l['columns']) #TODO parameter pour scanner ou non la db
else :
print('Table with geom are NOT auto-published')

try:
with open('app/motd.txt','r') as f:
print(f.read())
#### TRAITEMENT DU FICHIER DE CONFIG layers.toml ####
with open('layers.toml','r') as f:
tom = toml.load(f)
for c in tom['collection']: #Multi-layers tiles
layers_list=list()
for l in c['layer']:
layers_list.append( Layer(layer_name=l['name'], table_name = l['table_name'], dbparam=app.config['DB'], columns=l.get('columns',None), minzoom=l.get('minzoom',None), maxzoom=l.get('maxzoom',None) , geometry_column = l.get('geometry_column','geom') ) )
app.config['data'][ c['name'] ] = LayerCollection(collection_name=c['name'], layers = layers_list)
for l in tom['layers']: #Simple layer tiles
app.config['data'][ l['name'] ] = Layer(layer_name=l['name'], table_name=l['table_name'], dbparam=app.config['DB'], columns=l.get('columns',None), minzoom=l.get('minzoom',None), maxzoom=l.get('maxzoom',None) , geometry_column = l.get('geometry_column','geom') )
except FileNotFoundError:
pass
print('{} geo-layers found'.format(len(app.config['layers'].get('layer',list()))) )
print("No layers.toml file found")
print('🌐 \033[1;32;40m {} layers or collections \033[0m'.format(len( app.config['data'] )) )
for k,v in app.config['data'].items():
if isinstance(v,LayerCollection):
print('- Collection: {}'.format(v.collection_name) )
for l in v.layers:
print(' - Layer: {} ("{}")'.format(l.layer_name, l.table_name) )
else :
print('- Layer: {} ("{}")'.format(v.layer_name, v.table_name) )
return app
8 changes: 8 additions & 0 deletions app/memo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO random_points (geom)
SELECT
(st_dump(ST_GeneratePoints(
st_setsrid(ST_MakeBox2D(
st_setsrid(st_point(-2,42),4326), st_setsrid(st_point(8,51),4326)
), 4326)
, 1))).geom
FROM generate_series(1,200000)
Loading

0 comments on commit ebc273e

Please sign in to comment.