Changeset 867

Show
Ignore:
Timestamp:
07/17/08 12:03:33 (6 months ago)
Author:
elemoine
Message:

enhanced Map Fish? Server code, r=sypasche, see Releases/0.3/HowToMigrateToMapFishServer0.3 to migrate your application code. (closes #184)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MapFish/client/examples/geostat/choropleths.html

    r426 r867  
    5050                          ['death_rt', 'Death Rate'], 
    5151                          ['fertility', 'Fertility']], 
    52             'url': mapfish.SERVER_BASE_URL + "/countries", 
     52            'url': mapfish.SERVER_BASE_URL + "countries", 
    5353            'loadMask' : {msg: 'Loading Data...', msgCls: 'x-mask-loading'} 
    5454        }); 
  • trunk/MapFish/client/examples/geostat/proportionalSymbols.html

    r426 r867  
    4646            'nameAttribute': 'name', 
    4747            'indicators': [['population', 'Population']], 
    48             'url': mapfish.SERVER_BASE_URL + "/cities", 
     48            'url': mapfish.SERVER_BASE_URL + "cities", 
    4949            'loadMask' : {msg: 'Loading Data...', msgCls: 'x-mask-loading'} 
    5050        }); 
  • trunk/MapFish/client/examples/search/c2corg.html

    r686 r867  
    9696                    searchTolerance: 10 
    9797                }, { 
    98                     url: mapfish.SERVER_BASE_URL + 'c2corg', 
     98                    url: mapfish.SERVER_BASE_URL + 'summits', 
    9999                    params: { 
    100100                        maxfeatures: 10 
  • trunk/MapFish/server/python/mapfish/sqlalchemygeom.py

    r416 r867  
    1717# along with MapFish.  If not, see <http://www.gnu.org/licenses/>. 
    1818# 
     19 
     20__all__ = ['Geometry', 'GeometryTableMixIn'] 
    1921 
    2022 
     
    6062 
    6163from sqlalchemy.types import TypeEngine 
     64from sqlalchemy import Table 
    6265from shapely.wkb import loads 
     66 
     67from geojson import Feature 
    6368 
    6469class Geometry(TypeEngine): 
     
    8792        else: 
    8893            return loads(value.decode('hex')) 
     94 
     95class GeometryTableMixIn(object): 
     96    exported_keys = None 
     97    __geometry_column__ = None 
     98    __primary_key_column__ = None 
     99 
     100    def _getfid(self): 
     101        return getattr(self, self.primary_key_column().name) 
     102 
     103    def _setfid(self, val): 
     104        setattr(self, self.primary_key_column().name, val) 
     105 
     106    fid = property(_getfid, _setfid) 
     107 
     108    def _getgeom(self): 
     109        return getattr(self, self.geometry_column().name) 
     110 
     111    def _setgeom(self, val): 
     112        setattr(self, self.geometry_column().name, val) 
     113 
     114    geometry = property(_getgeom, _setgeom) 
     115 
     116    def __getitem__(self, key): 
     117        return getattr(self, key) 
     118 
     119    def __setitem__(self, key, val): 
     120         if key in self.__table__.c.keys(): 
     121             setattr(self, key, val) 
     122 
     123    def __contains__(self, key): 
     124        return hasattr(self, key) 
     125 
     126    @classmethod 
     127    def geometry_column(cls): 
     128        """ Returns the table's geometry column or None if the table has no geometry column. """ 
     129        if not cls.__geometry_column__: 
     130            columns = [c for c in cls.__table__.columns if isinstance(c.type, Geometry)] 
     131            if not columns: 
     132                return None 
     133            elif len(columns) > 1: 
     134                raise Exception("There is more than one geometry column") 
     135            else: 
     136                cls.__geometry_column__ = columns.pop() 
     137        return cls.__geometry_column__ 
     138 
     139    @classmethod 
     140    def primary_key_column(cls): 
     141        """ Returns the table's primary key column """ 
     142        if not cls.__primary_key_column__: 
     143            keys = [k for k in cls.__table__.primary_key] 
     144            if not keys: 
     145                raise Exception("No primary key found !") 
     146            elif len(keys) > 1: 
     147                raise Exception("There is more than one primary key column") 
     148            else: 
     149                cls.__primary_key_column__ = keys.pop() 
     150        return cls.__primary_key_column__ 
     151             
     152    def toFeature(self): 
     153        if not self.exported_keys: 
     154            exported = self.__table__.c.keys() 
     155        else: 
     156            exported = self.exported_keys 
     157 
     158        fid_column = self.primary_key_column().name 
     159        geom_column = self.geometry_column().name 
     160 
     161        attributes = {} 
     162        for k in exported: 
     163            k = str(k) 
     164            if k != fid_column and k != geom_column and hasattr(self, k): 
     165                attributes[k] = getattr(self, k) 
     166 
     167        return Feature(id=self.fid,  
     168                       geometry=self.geometry, 
     169                       properties=attributes) 
  • trunk/MapFish/server/python/mapfish/templates/controller.py_tmpl

    r819 r867  
    1818# 
    1919 
    20 import logging 
    21  
    22 from sqlalchemy.sql import and_ 
    23  
    24 from shapely.geometry import asShape 
    25  
    2620from ${basePkg}.lib.base import * 
    2721from ${basePkg}.model.${modName} import ${modelClass} 
    2822 
    29 from mapfish.pfpfeature import FeatureCollection 
    30 from mapfish.plugins.search import Search 
    31  
    32 import geojson 
    33  
    34 log = logging.getLogger(__name__) 
     23from mapfish.lib.filters import * 
     24from mapfish.lib.protocol import Protocol, create_default_filter 
    3525 
    3626class ${contrClass}Controller(BaseController): 
    37     def get(self): 
    38         search = Search( 
    39             ${modelClass}._table.c._mf_fid, 
    40             ${modelClass}._table.c._mf_geom, 
    41             ${epsg}, '${units}') 
    42         expr = search.buildExpression(request) 
     27    readonly = False # if set to True, only GET is supported 
     28 
     29    def __init__(self): 
     30        self.protocol = Protocol(model.Session, ${modelClass}, self.readonly) 
     31 
     32    def index(self, format='json'): 
     33        """GET /: return all features.""" 
     34        # If no filter argument is passed to the protocol index method 
     35        # then the default MapFish filter is used. This default filter 
     36        # is constructed based on the box, lon, lat, tolerance GET 
     37        # params. 
    4338        # 
    44         # CUSTOM CODE GOES HERE 
     39        # If you need your own filter with application-specific params  
     40        # taken into acount, create your own filter and pass it to the 
     41        # protocol index method. 
    4542        # 
    46         # Here you can augment the expression with your own app-specific 
    47         # filters. 
     43        # E.g. 
    4844        # 
    49         # Example: 
    50         # if 'name' in request.params: 
    51         #     e = model.summits_table.c.name.op('ilike')('%' + request.params['name']  + '%') 
    52         #     # update query expression 
    53         #     if expr is not None: 
    54         #         expr = and_(expr, e) 
    55         #     else: 
    56         #         expr = e 
     45        # default_filter = create_default_filter( 
     46        #     request, 
     47        #     ${modelClass}.primary_key_column(), 
     48        #     ${modelClass}.geometry_column() 
     49        # ) 
     50        # compare_filter = comparison.Comparison( 
     51        #     comparison.Comparison.ILIKE, 
     52        #     ${modelClass}.mycolumnname, 
     53        #     value=myvalue 
     54        # ) 
     55        # filter = logical.Logical(logical.Logical.AND, [default_filter, compare_filter]) 
     56        # return self.protocol.index(request, response, format=format, filter=filter) 
    5757        # 
    58         ${pluralName} = search.query( 
    59             model.Session, ${modelClass}, ${modelClass}._table, expr) 
    60         if len(${pluralName}) > 0: 
    61             return geojson.dumps( 
    62                 FeatureCollection([o.toFeature() for o in ${pluralName}])) 
     58        return self.protocol.index(request, response, format=format) 
    6359 
    64     # 
    65     # The post, put and delete methods are used for feature editing. If you 
    66     # don't want feature editing, you can just not add routes to these methods 
    67     # in config/routing.py. If you don't want feature editing and care about 
    68     # having unneeded code, you can remove these methods entirely. 
    69     # 
     60    def show(self, id, format='json'): 
     61        """GET /id: Show a specific feature.""" 
     62        return self.protocol.show(request, response, id, format=format) 
    7063 
    71     def post(self): 
    72         content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH'])) 
    73         factory = lambda ob: geojson.GeoJSON.to_instance(ob) 
    74         collection = geojson.loads(content, object_hook=factory) 
    75         if not isinstance(collection, geojson.feature.FeatureCollection): 
    76             response.status_code = 400 
    77             return 
    78         ${pluralName} = [] 
    79         for feature in collection.features: 
    80             create = False 
    81             ${singularName} = None 
    82             if isinstance(feature.id, int): 
    83                 ${singularName} = model.Session.query(${modelClass}).get(feature.id) 
    84             if ${singularName} is None: 
    85                 ${singularName} = ${modelClass}(asShape(feature.geometry)) 
    86                 create = True 
    87             for key in feature.properties: 
    88                 ${singularName}[key] = feature.properties[key] 
    89             if create: 
    90                 model.Session.save(${singularName}) 
    91             ${pluralName}.append(${singularName}) 
    92         model.Session.commit() 
    93         response.status_code = 201 
    94         if len(${pluralName}) > 0: 
    95             return geojson.dumps(FeatureCollection([o.toFeature() for o in ${pluralName}])) 
    96         return 
     64    def create(self): 
     65        """POST /: Create a new feature.""" 
     66        return self.protocol.create(request, response) 
    9767 
    98     def put(self): 
    99         fid = self.getFid() 
    100         if fid is None: 
    101             return self.post() 
    102         ${singularName} = model.Session.query(${modelClass}).get(fid) 
    103         if ${singularName} is None: 
    104             response.status_code = 404 
    105             return 
    106         content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH'])) 
    107         factory = lambda ob: geojson.GeoJSON.to_instance(ob) 
    108         feature = geojson.loads(content, object_hook=factory) 
    109         if not isinstance(feature, geojson.feature.Feature): 
    110             response.status_code = 400 
    111             return response 
    112         ${singularName}.geometry = asShape(feature.geometry) 
    113         for key in feature.properties: 
    114             ${singularName}[key] = feature.properties[key] 
    115         model.Session.commit() 
    116         response.status_code = 201 
    117         return geojson.dumps(${singularName}.toFeature()) 
     68    def update(self, id): 
     69        """PUT /id: Update an existing feature.""" 
     70        return self.protocol.update(request, response, id) 
    11871 
    119     def delete(self): 
    120         fid = self.getFid() 
    121         if fid is None: 
    122             response.status_code = 400 
    123             return 
    124         ${singularName} = model.Session.query(${modelClass}).get(fid) 
    125         if ${singularName} is None: 
    126             response.status_code = 404 
    127             return 
    128         model.Session.delete(${singularName}) 
    129         model.Session.commit() 
    130         response.status_code = 204 
    131         return 
    132  
    133     def getFid(self): 
    134         fid = None 
    135         path = request.path_info.split("/") 
    136         if len(path) > 1: 
    137             pathPieces = path[-1].split(".") 
    138             if pathPieces[0].isdigit(): 
    139                 fid = int(pathPieces[0]) 
    140         return fid 
     72    def delete(self, id): 
     73        """PUT /id: Update an existing feature.""" 
     74        return self.protocol.delete(request, response, id) 
  • trunk/MapFish/server/python/mapfish/templates/model.py_tmpl

    r819 r867  
    1818# 
    1919 
    20  
    2120from pylons import config 
    2221 
     
    2524 
    2625from mapfish.sqlalchemygeom import Geometry 
    27 from mapfish.pfpfeature import Feature 
     26from mapfish.sqlalchemygeom import GeometryTableMixIn 
    2827 
    29 ${modelTabObj} = Table('${table}', 
     28${modelTabObj} = Table( 
     29    '${table}', 
    3030    MetaData(config['pylons.g'].sa_${db}_engine), 
    31     Column('${idColName}', types.${idColType}, key='_mf_fid', primary_key=True), 
    32     Column('${geomColName}', Geometry(${epsg}), key='_mf_geom'), 
     31    Column('${geomColName}', Geometry(${epsg})), 
    3332    autoload=True) 
    3433 
    35 class ${modelClass}(object): 
    36     _table = ${modelTabObj} 
    37  
    38     def __init__(self, geometry): 
    39         self._mf_geom = geometry 
    40  
    41     def _getgeom(self): 
    42         return self._mf_geom 
    43  
    44     def _setgeom(self, val): 
    45         self._mf_geom = val 
    46  
    47     geometry = property(_getgeom, _setgeom) 
    48  
    49     def __getitem__(self, key): 
    50         return getattr(self, key) 
    51  
    52     def __setitem__(self, key, val): 
    53         if key in self._table.c.keys(): 
    54             setattr(self, key, val) 
    55  
    56     def __contains__(self, key): 
    57         return hasattr(self, key) 
    58  
    59     def toFeature(self): 
    60         attributes = {} 
    61         for k in self._table.c.keys(): 
    62             k = k.encode('ascii') 
    63             if k != '_mf_fid' and k != '_mf_geom' and hasattr(self, k): 
    64                 attributes[k] = getattr(self, k) 
    65         return Feature(id=self._mf_fid, geometry=self._mf_geom, **attributes) 
     34class ${modelClass}(GeometryTableMixIn): 
     35    # for GeometryTableMixIn to do its job the __table__ property 
     36    # must be set here 
     37    __table__ = ${modelTabObj} 
    6638 
    6739mapper(${modelClass}, ${modelTabObj}) 
  • trunk/MapFishSample/MapFishSample.egg-info/PKG-INFO

    r89 r867  
    11Metadata-Version: 1.0 
    22Name: MapFishSample 
    3 Version: 0.0.0dev 
     3Version: 0.0.0dev-r855 
    44Summary: UNKNOWN 
    55Home-page: UNKNOWN 
  • trunk/MapFishSample/MapFishSample.egg-info/SOURCES.txt

    r89 r867  
     1COPYING 
     2COPYING.LESSER 
    13MANIFEST.in 
    24README.txt 
     5development.ini 
     6layers.ini 
     7mapfishsample.ini.in 
     8mapfishsample.wsgi.in 
    39setup.cfg 
    410setup.py 
     11test.ini 
    512MapFishSample.egg-info/PKG-INFO 
    613MapFishSample.egg-info/SOURCES.txt 
     
    815MapFishSample.egg-info/entry_points.txt 
    916MapFishSample.egg-info/paste_deploy_config.ini_tmpl 
     17MapFishSample.egg-info/paster_plugins.txt 
    1018MapFishSample.egg-info/requires.txt 
    1119MapFishSample.egg-info/top_level.txt 
     20docs/index.txt 
     21ez_setup/README.txt 
     22ez_setup/__init__.py 
    1223mapfishsample/__init__.py 
    1324mapfishsample/websetup.py 
     
    1728mapfishsample/config/routing.py 
    1829mapfishsample/controllers/__init__.py 
     30mapfishsample/controllers/cities.py 
     31mapfishsample/controllers/countries.py 
     32mapfishsample/controllers/epfl.py 
    1933mapfishsample/controllers/error.py 
     34mapfishsample/controllers/lines.py 
     35mapfishsample/controllers/points.py 
     36mapfishsample/controllers/polygons.py 
     37mapfishsample/controllers/printer.py 
     38mapfishsample/controllers/summits.py 
    2039mapfishsample/controllers/template.py 
    2140mapfishsample/lib/__init__.py 
     
    2443mapfishsample/lib/helpers.py 
    2544mapfishsample/model/__init__.py 
     45mapfishsample/model/lines.py 
     46mapfishsample/model/points.py 
     47mapfishsample/model/polygons.py 
     48mapfishsample/model/summits.py 
     49mapfishsample/public/allfiles.html 
     50mapfishsample/public/base.css 
     51mapfishsample/public/bullet.gif 
    2652mapfishsample/public/index.html 
     53mapfishsample/public/mapfish.png 
     54mapfishsample/public/demos/c2corg.png 
     55mapfishsample/public/demos/epfl.png 
     56mapfishsample/public/demos/index.html 
     57mapfishsample/public/demos/world_factbk.png 
     58mapfishsample/public/demos/c2corg/AQUA.png 
     59mapfishsample/public/demos/c2corg/information-box.png 
     60mapfishsample/public/demos/c2corg/information.png 
     61mapfishsample/public/demos/c2corg/search.html 
     62mapfishsample/public/demos/geostat/geostat.html 
     63mapfishsample/public/demos/routing/epfl.html 
     64mapfishsample/public/lib/Jugl.js 
     65mapfishsample/public/tests/list-tests.html 
     66mapfishsample/public/tests/run-tests.html 
     67mapfishsample/public/tests/run-tests.html.upstream 
     68mapfishsample/public/tests/test_examples.html 
     69mapfishsample/public/tests/tests-wrapper.html 
     70mapfishsample/public/tests/tree/test_checkbox.html 
    2771mapfishsample/tests/__init__.py 
    2872mapfishsample/tests/test_models.py 
    2973mapfishsample/tests/functional/__init__.py 
     74mapfishsample/tests/functional/test_cities.py 
     75mapfishsample/tests/functional/test_countries.py 
     76mapfishsample/tests/functional/test_epfl.py 
     77mapfishsample/tests/functional/test_lines.py 
     78mapfishsample/tests/functional/test_points.py 
     79mapfishsample/tests/functional/test_polygons.py 
     80mapfishsample/tests/functional/test_summits.py 
  • trunk/MapFishSample/MapFishSample.egg-info/paster_plugins.txt

    r2 r867  
    11Pylons 
    22WebHelpers 
     3MapFish 
    34PasteScript 
  • trunk/MapFishSample/mapfishsample.ini.in

    r736 r867  
    4242 
    4343# database configuration 
    44 sqlalchemy.routing.url = %DB_ROUTING_URL% 
    45 sqlalchemy.search.url = %DB_SEARCH_URL% 
    46 sqlalchemy.geostat.url = %DB_GEOSTAT_URL% 
     44sqlalchemy.mapfishsample.url = %DB_URL% 
    4745 
    4846# If you'd like to fine-tune the individual locations of the cache data dirs 
  • trunk/MapFishSample/mapfishsample/config/environment.py

    r89 r867  
    3232    # Pylons config options) 
    3333 
    34     config['pylons.g'].sa_routing_engine = engine_from_config(config, 'sqlalchemy.routing.') 
    35     config['pylons.g'].sa_search_engine = engine_from_config(config, 'sqlalchemy.search.') 
    36     config['pylons.g'].sa_geostat_engine = engine_from_config(config, 'sqlalchemy.geostat.') 
     34    config['pylons.g'].sa_mapfishsample_engine = engine_from_config(config, 'sqlalchemy.mapfishsample.') 
  • trunk/MapFishSample/mapfishsample/config/routing.py

    r736 r867  
    2222    printer.addRoutes(map, 'print/', 'printer') 
    2323 
    24     map.connect('c2corg/', controller='c2corg', action='show', conditions=dict(method=['GET'])) 
    25     map.connect('c2corg/:(id).:(format)', controller='c2corg', action='show', conditions=dict(method=['GET'])) 
    26     map.connect('countries/', controller='countries', action='show', conditions=dict(method=['GET'])) 
    27     map.connect('countries/:(id).:(format)', controller='countries', action='show', conditions=dict(method=['GET'])) 
    28     map.connect('cities/', controller='cities', action='show', conditions=dict(method=['GET'])) 
    29     map.connect('cities/:(id).:(format)', controller='cities', action='show', conditions=dict(method=['GET'])) 
     24    map.resource('summit', 'summits') 
     25    map.resource('country', 'countries') 
     26    map.resource('city', 'cities') 
     27    map.resource('polygon', 'polygons') 
     28    map.resource('line', 'lines') 
     29    map.resource('point', 'points') 
     30 
    3031    map.connect(':controller/:action/:id') 
    3132    map.connect('*url', controller='template', action='view') 
  • trunk/MapFishSample/mapfishsample/controllers/cities.py

    r414 r867  
    2020import logging 
    2121 
    22 from sqlalchemy.sql import and_ 
    23  
    2422from mapfishsample.lib.base import * 
    2523 
    26 from mapfish.pfpfeature import FeatureCollection 
    27 from mapfish.plugins.search import Search 
    28  
    29 import geojson 
     24from mapfish.lib.filters import * 
     25from mapfish.lib.protocol import Protocol, create_default_filter 
    3026 
    3127log = logging.getLogger(__name__) 
    3228 
    3329class CitiesController(BaseController): 
     30    readonly = True 
    3431 
    35     def show(self): 
    36         search = Search( 
    37             model.cities_table.c.id, 
    38             model.cities_table.c.the_geom, 
    39             4326, 'degrees') 
    40         expr = search.buildExpression(request) 
    41         objects = search.query(model.Session, model.City, model.cities_table, expr) 
    42         if len(objects) != 0: 
    43             return geojson.dumps(FeatureCollection([f.toFeature() for f in objects])) 
     32    def __init__(self): 
     33        self.protocol = Protocol(model.Session, model.City, self.readonly) 
     34 
     35    def index(self, format='json'): 
     36        """GET /: return all features.""" 
     37        # If no filter argument is passed to the protocol index method 
     38        # then the default MapFish filter is used. This default filter 
     39        # is constructed based on the box, lon, lat, tolerance GET 
     40        # params. 
     41        # 
     42        # If you need your own filter with application-specific params  
     43        # taken into acount, create your own filter and pass it to the 
     44        # protocol index method. 
     45        # 
     46        # E.g. 
     47        # 
     48        # default_filter = create_default_filter( 
     49        #     request, 
     50        #     City.primary_key_column(), 
     51        #     City.geometry_column() 
     52        # ) 
     53        # compare_filter = comparison.Comparison( 
     54        #     comparison.Comparison.ILIKE, 
     55        #     City.mycolumnname, 
     56        #     value=myvalue 
     57        # ) 
     58        # filter = logical.Logical(logical.Logical.AND, [default_filter, compare_filter]) 
     59        # return self.protocol.index(request, response, format=format, filter=filter) 
     60        # 
     61        return self.protocol.index(request, response, format=format) 
     62 
     63    def show(self, id, format='json'): 
     64        """GET /id: Show a specific feature.""" 
     65        return self.protocol.show(request, response, id, format=format) 
     66 
     67    def create(self): 
     68        """POST /: Create a new feature.""" 
     69        return self.protocol.create(request, response) 
     70 
     71    def update(self, id): 
     72        """PUT /id: Update an existing feature.""" 
     73        return self.protocol.update(request, response, id) 
     74 
     75    def delete(self, id): 
     76        """PUT /id: Update an existing feature.""" 
     77        return self.protocol.delete(request, response, id)#  
  • trunk/MapFishSample/mapfishsample/controllers/countries.py

    r414 r867  
    2020import logging 
    2121 
    22 from sqlalchemy.sql import and_ 
    23  
    2422from mapfishsample.lib.base import * 
    2523 
    26 from mapfish.pfpfeature import FeatureCollection 
    27 from mapfish.plugins.search import Search 
    28  
    29 import geojson 
     24from mapfish.lib.filters import * 
     25from mapfish.lib.protocol import Protocol, create_default_filter 
    3026 
    3127log = logging.getLogger(__name__) 
    3228 
    3329class CountriesController(BaseController): 
     30    readonly = True 
    3431 
    35     def show(self): 
    36         search = Search( 
    37             model.countries_table.c.gid, 
    38             model.countries_table.c.simplify, 
    39             4326, 'degrees') 
    40         expr = search.buildExpression(request) 
    41         objects = search.query(model.Session, model.Country, model.countries_table, expr) 
    42         if len(objects) != 0: 
    43             return geojson.dumps(FeatureCollection([f.toFeature() for f in objects])) 
     32    def __init__(self): 
     33        self.protocol = Protocol(model.Session, model.Country, self.readonly) 
     34 
     35    def index(self, format='json'): 
     36        """GET /: return all features.""" 
     37        # If no filter argument is passed to the protocol index method 
     38        # then the default MapFish filter is used. This default filter 
     39        # is constructed based on the box, lon, lat, tolerance GET 
     40        # params. 
     41        # 
     42        # If you need your own filter with application-specific params  
     43        # taken into acount, create your own filter and pass it to the 
     44        # protocol index method. 
     45        # 
     46        # E.g. 
     47        # 
     48        # default_filter = create_default_filter( 
     49        #     request, 
     50        #     Country.primary_key_column(), 
     51        #     Country.geometry_column() 
     52        # ) 
     53        # compare_filter = comparison.Comparison( 
     54        #     comparison.Comparison.ILIKE, 
     55        #     Country.mycolumnname, 
     56        #     value=myvalue 
     57        # ) 
     58        # filter = logical.Logical(logical.Logical.AND, [default_filter, compare_filter]) 
     59        # return self.protocol.index(request, response, format=format, filter=filter) 
     60        # 
     61        return self.protocol.index(request, response, format=format) 
     62 
     63    def show(self, id, format='json'): 
     64        """GET /id: Show a specific feature.""" 
     65        return self.protocol.show(request, response, id, format=format) 
     66 
     67    def create(self): 
     68        """POST /: Create a new feature.""" 
     69        return self.protocol.create(request, response) 
     70 
     71    def update(self, id): 
     72        """PUT /id: Update an existing feature.""" 
     73        return self.protocol.update(request, response, id) 
     74 
     75    def delete(self, id): 
     76        """PUT /id: Update an existing feature.""" 
     77        return self.protocol.delete(request, response, id) 
  • trunk/MapFishSample/mapfishsample/controllers/epfl.py

    r414 r867  
    2222from mapfishsample.lib.base import * 
    2323from mapfish.plugins import pgrouting 
    24 from mapfish.pfpfeature import FeatureCollection 
    2524 
    26 import geojson 
     25from geojson import FeatureCollection, dumps 
    2726 
    2827log = logging.getLogger(__name__) 
     
    4544            cost = "length::float8" 
    4645             
    47         route = pgrouting.shortest_path(config['pylons.g'].sa_routing_engine, 
     46        route = pgrouting.shortest_path(config['pylons.g'].sa_mapfishsample_engine, 
    4847                                        "SELECT gid AS id, node1_id::int4 AS source, node2_id::int4 AS target, %(cost)s AS cost FROM lines2"%{'cost': cost}, 
    4948                                        int(source_id), int(target_id)).fetchall() 
     
    5857        result = FeatureCollection([line.toFeature() for line in lines if line is not None and line.geom is not None]) 
    5958 
    60         result.extend([source_f, target_f]) 
     59        result.features.extend([source_f, target_f]) 
    6160        #length = sum([line.length for line in lines if line is not None]) 
    6261 
    63         return geojson.dumps(result) 
     62        return dumps(result) 
    6463 
  • trunk/MapFishSample/mapfishsample/model/__init__.py

    r452 r867  
    2626 
    2727from mapfish.sqlalchemygeom import Geometry 
    28 from mapfish.pfpfeature import Feature 
     28from mapfish.sqlalchemygeom import GeometryTableMixIn 
    2929 
    30 # Global session manager.  Session() returns the session object appropriate for the current web request. 
    31 binds={"nodes2": MetaData(config['pylons.g'].sa_routing_engine), 
    32        "lines2": MetaData(config['pylons.g'].sa_routing_engine), 
    33        "sommets_out": MetaData(config['pylons.g'].sa_search_engine), 
    34        "world_factbk_simplified": MetaData(config['pylons.g'].sa_geostat_engine), 
    35        "world_cities": MetaData(config['pylons.g'].sa_geostat_engine)} 
     30from geojson import Feature 
    3631 
    37 Session = scoped_session(sessionmaker(transactional=True, autoflush=True, binds=binds)) 
     32Session = scoped_session(sessionmaker(transactional=True, autoflush=True)) 
    3833 
    3934## routing  
    40 nodes_table = Table('nodes2', MetaData(config['pylons.g'].sa_routing_engine), 
     35nodes_table = Table('nodes2', MetaData(config['pylons.g'].sa_mapfishsample_engine), 
    4136                    Column('node_id', types.Integer, primary_key=True), 
    4237                    Column('room', types.String, unique=True), 
     
    4540 
    4641class Node(object): 
     42    __table__ = nodes_table 
    4743    def toFeature(self): 
    4844        return Feature(id=int(self.node_id), geometry=self.geom, 
    49                        room=str(self.room), floor=str(self.level)
     45                       properties={'room': str(self.room), 'floor': str(self.level)}
    5046 
    51  
    52 lines_table = Table('lines2', MetaData(config['pylons.g'].sa_routing_engine), 
     47lines_table = Table('lines2', MetaData(config['pylons.g'].sa_mapfishsample_engine), 
    5348                    Column('gid', types.Integer, primary_key=True), 
    5449                    Column('length', types.Float), 
     
    5853    def toFeature(self): 
    5954        return Feature(id=int(self.gid), geometry=self.geom, 
    60                        distance=float(self.length)
     55                       properties={'distance': float(self.length)}
    6156 
    6257mapper(Node, nodes_table) 
    6358mapper(Line, lines_table) 
    6459 
    65 ## c2c org 
    66 summits_table = Table('sommets_out', MetaData(config['pylons.g'].sa_search_engine), 
    67                       Column('sommet_id', types.Integer, primary_key=True), 
    68                       Column('elevation', types.Integer), 
    69                       Column('name', types.Unicode), 
    70                       Column('geom', Geometry(32768))) 
    71  
    72 class Summit(object): 
    73     def __str__(self): 
    74         return self.name 
    75  
    76     def toFeature(self): 
    77         return Feature(id=self.sommet_id, geometry=self.geom, 
    78                        elevation=float(self.elevation), 
    79                        name=self.name) 
    80  
    81 mapper(Summit, summits_table) 
    82  
    8360## world_factbk 
    84 countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_geostat_engine), 
     61countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfishsample_engine), 
    8562                        Column('gid', types.Integer, primary_key=True), 
    8663                        Column('country', types.String), 
     
    9067                        Column('simplify', Geometry)) 
    9168 
    92 class Country(object): 
    93     def __str__(self): 
    94         return self.country 
    95  
    96     def toFeature(self): 
    97         return Feature(id=self.gid, geometry=self.simplify, country=self.country, 
    98                        birth_rt=self.birth_rt, death_rt=self.death_rt, 
    99                        fertility=self.fertility) 
     69class Country(GeometryTableMixIn): 
     70    __table__ = countries_table 
    10071 
    10172mapper(Country, countries_table) 
    10273 
    10374## world_cities 
    104 cities_table = Table('world_cities', MetaData(config['pylons.g'].sa_geostat_engine), 
     75cities_table = Table('world_cities', MetaData(config['pylons.g'].sa_mapfishsample_engine), 
    10576                     Column('id', types.Integer, primary_key=True), 
    10677                     Column('ufi', types.Integer), 
     
    11283                     Column('the_geom', Geometry(4326))) 
    11384 
    114 class City(object): 
    115     def __str__(self): 
    116         return self.name 
    117  
    118     def toFeature(self): 
    119         return Feature(id=self.id, geometry=self.the_geom, ufi=self.ufi, 
    120                        admin_code=self.admin_code, mgcc=self.mgcc, name=self.name, 
    121                        attrib=self.attrib, population=self.population) 
     85class City(GeometryTableMixIn): 
     86    __table__ = cities_table 
    12287 
    12388mapper(City, cities_table) 
  • trunk/MapFishSample/mapfishsample/public/demos/c2corg/search.html

    r687 r867  
    413413                  'searchTolerance': 4 
    414414              }, { 
    415                   'url': '../../c2corg', 
     415                  'url': '../../summits', 
    416416                  'params': { 
    417417                      'maxfeatures': 10 
     
    423423 
    424424      var mediator = new mapfish.SearchMediator( 
    425           '../../c2corg', 
     425          '../../summits', 
    426426          function(features) { 
    427427              featureStore.removeAll(); 
  • trunk/mapfishsample/configs/aravis.wrk.cby.camptocamp.com

    r736 r867  
    11export DEBUG="true" 
    22 
    3 export DB_ROUTING_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/epfl 
    4 export DB_SEARCH_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/c2corg 
    5 export DB_GEOSTAT_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/geostat 
     3export DB_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/mapfishsample 
    64 
    75export MVN="/home/elemoine/soft/apache-maven-2.0.8/bin/mvn" 
  • trunk/mapfishsample/configs/defaults

    r737 r867