MapFish Server Frequently Asked Questions
I want to use PostgreSQL types numeric and/or decimal but get json errors, what can I do?
Use asdecimal=False in your model definition. Example:
countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfish_engine), Column('gid', types.Integer, primary_key=True), Column('simplify', Geometry), Column('test_real', types.Float), Column('test_numeric', types.Numeric(asdecimal=False)), Column('test_decimal', types.Numeric(asdecimal=False)), autoload=True)
See the corresponding section in the SQLAlchemy doc.
I do not want to dump all table fields into GeoJSON, what can I do?
Find the following code in model/mytable.py :
mytable_table = Table('mytable', MetaData(config['pylons.g'].sa_geostat_engine), Column('gid', types.Integer, key='_mf_fid', primary_key=True), Column('geom', Geometry(27572), key='_mf_geom'), autoload=True)
Remove autoload=True and add in the list the fields you want to see.
My table isn't in the "public" schema, how does MapFish deal with that?
Currently (version 0.2) it doesn't. In the sense that you can't specify the schema your table is in when defining your layer in layers.ini.
Once you've created your layer using paster mf-layer edit your layer model file and pass a schema to the Table constructor. Example:
countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfish_engine), Column('gid', types.Integer, primary_key=True), Column('simplify', Geometry), Column('test_real', types.Float), Column('test_numeric', types.Numeric(asdecimal=False)), Column('test_decimal', types.Numeric(asdecimal=False)), autoload=True, schema=myschema)
My primary key is a sequence whose name isn't <pk_name>_seq, how does MapFish deal with that?
Currently (version 0.2) it doesn't. In the sense that you can't specify the name of the sequence when definining your layer in layers.ini.
Once you've created your layer using paster mf-layer edit your layer model file and pass a Sequence object the Column constructor associated with the public key. Example:
countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfish_engine), Column('gid', types.Integer, Sequence('countries_table_gid_seq'), primary_key=True), Column('simplify', Geometry), Column('test_real', types.Float), Column('test_numeric', types.Numeric(asdecimal=False)), Column('test_decimal', types.Numeric(asdecimal=False)), autoload=True)
If your sequence isn't in the "public" schema, use:
countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfish_engine), Column('gid', types.Integer, Sequence('countries_table_gid_seq', schema=myschema), primary_key=True), Column('simplify', Geometry), Column('test_real', types.Float), Column('test_numeric', types.Numeric(asdecimal=False)), Column('test_decimal', types.Numeric(asdecimal=False)), autoload=True, schema=myschema)
I want reprojected features in the GeoJSON response. How can I achieve that?
To achieve this you can inherit from the Search class (mapfish.plugins.Search) and override the query() method. Here is an example:
from mapfish.plugins import Search class MySearch(Search): def query(self, session, obj, tableObj, expr): return session.query(obj).from_statement( select([func.transform( tableObj.c.the_geom, 27572, type_=Geometry).label('the_geom'), tableObj.c.ogc_fid, tableObj.c.id_dep], expr).limit(self.limit)).all()