Changeset 867
- Timestamp:
- 07/17/08 12:03:33 (6 months ago)
- Files:
-
- trunk/MapFish/client/examples/geostat/choropleths.html (modified) (1 diff)
- trunk/MapFish/client/examples/geostat/proportionalSymbols.html (modified) (1 diff)
- trunk/MapFish/client/examples/search/c2corg.html (modified) (1 diff)
- trunk/MapFish/server/python/mapfish/lib (added)
- trunk/MapFish/server/python/mapfish/lib/__init__.py (added)
- trunk/MapFish/server/python/mapfish/lib/filters (added)
- trunk/MapFish/server/python/mapfish/lib/filters/__init__.py (added)
- trunk/MapFish/server/python/mapfish/lib/filters/comparison.py (added)
- trunk/MapFish/server/python/mapfish/lib/filters/featureid.py (added)
- trunk/MapFish/server/python/mapfish/lib/filters/logical.py (added)
- trunk/MapFish/server/python/mapfish/lib/filters/spatial.py (added)
- trunk/MapFish/server/python/mapfish/lib/protocol.py (added)
- trunk/MapFish/server/python/mapfish/pfpfeature.py (deleted)
- trunk/MapFish/server/python/mapfish/plugins/search.py (deleted)
- trunk/MapFish/server/python/mapfish/sqlalchemygeom.py (modified) (3 diffs)
- trunk/MapFish/server/python/mapfish/templates/controller.py_tmpl (modified) (1 diff)
- trunk/MapFish/server/python/mapfish/templates/model.py_tmpl (modified) (2 diffs)
- trunk/MapFishSample/MapFishSample.egg-info/PKG-INFO (modified) (1 diff)
- trunk/MapFishSample/MapFishSample.egg-info/SOURCES.txt (modified) (4 diffs)
- trunk/MapFishSample/MapFishSample.egg-info/paster_plugins.txt (modified) (1 diff)
- trunk/MapFishSample/layers.ini (added)
- trunk/MapFishSample/mapfishsample.ini.in (modified) (1 diff)
- trunk/MapFishSample/mapfishsample/config/environment.py (modified) (1 diff)
- trunk/MapFishSample/mapfishsample/config/routing.py (modified) (1 diff)
- trunk/MapFishSample/mapfishsample/controllers/c2corg.py (deleted)
- trunk/MapFishSample/mapfishsample/controllers/cities.py (modified) (1 diff)
- trunk/MapFishSample/mapfishsample/controllers/countries.py (modified) (1 diff)
- trunk/MapFishSample/mapfishsample/controllers/epfl.py (modified) (3 diffs)
- trunk/MapFishSample/mapfishsample/controllers/lines.py (added)
- trunk/MapFishSample/mapfishsample/controllers/points.py (added)
- trunk/MapFishSample/mapfishsample/controllers/polygons.py (added)
- trunk/MapFishSample/mapfishsample/controllers/summits.py (added)
- trunk/MapFishSample/mapfishsample/model/__init__.py (modified) (5 diffs)
- trunk/MapFishSample/mapfishsample/model/lines.py (added)
- trunk/MapFishSample/mapfishsample/model/points.py (added)
- trunk/MapFishSample/mapfishsample/model/polygons.py (added)
- trunk/MapFishSample/mapfishsample/model/summits.py (added)
- trunk/MapFishSample/mapfishsample/public/demos/c2corg/search.html (modified) (2 diffs)
- trunk/MapFishSample/mapfishsample/tests/functional/test_c2corg.py (deleted)
- trunk/MapFishSample/mapfishsample/tests/functional/test_lines.py (added)
- trunk/MapFishSample/mapfishsample/tests/functional/test_points.py (added)
- trunk/MapFishSample/mapfishsample/tests/functional/test_polygons.py (added)
- trunk/MapFishSample/mapfishsample/tests/functional/test_summits.py (added)
- trunk/mapfishsample/configs/aravis.wrk.cby.camptocamp.com (modified) (1 diff)
- trunk/mapfishsample/configs/defaults (modified) (1 diff)
- trunk/mapfishsample/configs/zuort.wrk.lsn.camptocamp.com (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MapFish/client/examples/geostat/choropleths.html
r426 r867 50 50 ['death_rt', 'Death Rate'], 51 51 ['fertility', 'Fertility']], 52 'url': mapfish.SERVER_BASE_URL + " /countries",52 'url': mapfish.SERVER_BASE_URL + "countries", 53 53 'loadMask' : {msg: 'Loading Data...', msgCls: 'x-mask-loading'} 54 54 }); trunk/MapFish/client/examples/geostat/proportionalSymbols.html
r426 r867 46 46 'nameAttribute': 'name', 47 47 'indicators': [['population', 'Population']], 48 'url': mapfish.SERVER_BASE_URL + " /cities",48 'url': mapfish.SERVER_BASE_URL + "cities", 49 49 'loadMask' : {msg: 'Loading Data...', msgCls: 'x-mask-loading'} 50 50 }); trunk/MapFish/client/examples/search/c2corg.html
r686 r867 96 96 searchTolerance: 10 97 97 }, { 98 url: mapfish.SERVER_BASE_URL + ' c2corg',98 url: mapfish.SERVER_BASE_URL + 'summits', 99 99 params: { 100 100 maxfeatures: 10 trunk/MapFish/server/python/mapfish/sqlalchemygeom.py
r416 r867 17 17 # along with MapFish. If not, see <http://www.gnu.org/licenses/>. 18 18 # 19 20 __all__ = ['Geometry', 'GeometryTableMixIn'] 19 21 20 22 … … 60 62 61 63 from sqlalchemy.types import TypeEngine 64 from sqlalchemy import Table 62 65 from shapely.wkb import loads 66 67 from geojson import Feature 63 68 64 69 class Geometry(TypeEngine): … … 87 92 else: 88 93 return loads(value.decode('hex')) 94 95 class 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 18 18 # 19 19 20 import logging21 22 from sqlalchemy.sql import and_23 24 from shapely.geometry import asShape25 26 20 from ${basePkg}.lib.base import * 27 21 from ${basePkg}.model.${modName} import ${modelClass} 28 22 29 from mapfish.pfpfeature import FeatureCollection 30 from mapfish.plugins.search import Search 31 32 import geojson 33 34 log = logging.getLogger(__name__) 23 from mapfish.lib.filters import * 24 from mapfish.lib.protocol import Protocol, create_default_filter 35 25 36 26 class ${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. 43 38 # 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. 45 42 # 46 # Here you can augment the expression with your own app-specific 47 # filters. 43 # E.g. 48 44 # 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) 57 57 # 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) 63 59 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) 70 63 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) 97 67 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) 118 71 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 18 18 # 19 19 20 21 20 from pylons import config 22 21 … … 25 24 26 25 from mapfish.sqlalchemygeom import Geometry 27 from mapfish. pfpfeature import Feature26 from mapfish.sqlalchemygeom import GeometryTableMixIn 28 27 29 ${modelTabObj} = Table('${table}', 28 ${modelTabObj} = Table( 29 '${table}', 30 30 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})), 33 32 autoload=True) 34 33 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) 34 class ${modelClass}(GeometryTableMixIn): 35 # for GeometryTableMixIn to do its job the __table__ property 36 # must be set here 37 __table__ = ${modelTabObj} 66 38 67 39 mapper(${modelClass}, ${modelTabObj}) trunk/MapFishSample/MapFishSample.egg-info/PKG-INFO
r89 r867 1 1 Metadata-Version: 1.0 2 2 Name: MapFishSample 3 Version: 0.0.0dev 3 Version: 0.0.0dev-r855 4 4 Summary: UNKNOWN 5 5 Home-page: UNKNOWN trunk/MapFishSample/MapFishSample.egg-info/SOURCES.txt
r89 r867 1 COPYING 2 COPYING.LESSER 1 3 MANIFEST.in 2 4 README.txt 5 development.ini 6 layers.ini 7 mapfishsample.ini.in 8 mapfishsample.wsgi.in 3 9 setup.cfg 4 10 setup.py 11 test.ini 5 12 MapFishSample.egg-info/PKG-INFO 6 13 MapFishSample.egg-info/SOURCES.txt … … 8 15 MapFishSample.egg-info/entry_points.txt 9 16 MapFishSample.egg-info/paste_deploy_config.ini_tmpl 17 MapFishSample.egg-info/paster_plugins.txt 10 18 MapFishSample.egg-info/requires.txt 11 19 MapFishSample.egg-info/top_level.txt 20 docs/index.txt 21 ez_setup/README.txt 22 ez_setup/__init__.py 12 23 mapfishsample/__init__.py 13 24 mapfishsample/websetup.py … … 17 28 mapfishsample/config/routing.py 18 29 mapfishsample/controllers/__init__.py 30 mapfishsample/controllers/cities.py 31 mapfishsample/controllers/countries.py 32 mapfishsample/controllers/epfl.py 19 33 mapfishsample/controllers/error.py 34 mapfishsample/controllers/lines.py 35 mapfishsample/controllers/points.py 36 mapfishsample/controllers/polygons.py 37 mapfishsample/controllers/printer.py 38 mapfishsample/controllers/summits.py 20 39 mapfishsample/controllers/template.py 21 40 mapfishsample/lib/__init__.py … … 24 43 mapfishsample/lib/helpers.py 25 44 mapfishsample/model/__init__.py 45 mapfishsample/model/lines.py 46 mapfishsample/model/points.py 47 mapfishsample/model/polygons.py 48 mapfishsample/model/summits.py 49 mapfishsample/public/allfiles.html 50 mapfishsample/public/base.css 51 mapfishsample/public/bullet.gif 26 52 mapfishsample/public/index.html 53 mapfishsample/public/mapfish.png 54 mapfishsample/public/demos/c2corg.png 55 mapfishsample/public/demos/epfl.png 56 mapfishsample/public/demos/index.html 57 mapfishsample/public/demos/world_factbk.png 58 mapfishsample/public/demos/c2corg/AQUA.png 59 mapfishsample/public/demos/c2corg/information-box.png 60 mapfishsample/public/demos/c2corg/information.png 61 mapfishsample/public/demos/c2corg/search.html 62 mapfishsample/public/demos/geostat/geostat.html 63 mapfishsample/public/demos/routing/epfl.html 64 mapfishsample/public/lib/Jugl.js 65 mapfishsample/public/tests/list-tests.html 66 mapfishsample/public/tests/run-tests.html 67 mapfishsample/public/tests/run-tests.html.upstream 68 mapfishsample/public/tests/test_examples.html 69 mapfishsample/public/tests/tests-wrapper.html 70 mapfishsample/public/tests/tree/test_checkbox.html 27 71 mapfishsample/tests/__init__.py 28 72 mapfishsample/tests/test_models.py 29 73 mapfishsample/tests/functional/__init__.py 74 mapfishsample/tests/functional/test_cities.py 75 mapfishsample/tests/functional/test_countries.py 76 mapfishsample/tests/functional/test_epfl.py 77 mapfishsample/tests/functional/test_lines.py 78 mapfishsample/tests/functional/test_points.py 79 mapfishsample/tests/functional/test_polygons.py 80 mapfishsample/tests/functional/test_summits.py trunk/MapFishSample/MapFishSample.egg-info/paster_plugins.txt
r2 r867 1 1 Pylons 2 2 WebHelpers 3 MapFish 3 4 PasteScript trunk/MapFishSample/mapfishsample.ini.in
r736 r867 42 42 43 43 # database configuration 44 sqlalchemy.routing.url = %DB_ROUTING_URL% 45 sqlalchemy.search.url = %DB_SEARCH_URL% 46 sqlalchemy.geostat.url = %DB_GEOSTAT_URL% 44 sqlalchemy.mapfishsample.url = %DB_URL% 47 45 48 46 # If you'd like to fine-tune the individual locations of the cache data dirs trunk/MapFishSample/mapfishsample/config/environment.py
r89 r867 32 32 # Pylons config options) 33 33 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 22 22 printer.addRoutes(map, 'print/', 'printer') 23 23 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 30 31 map.connect(':controller/:action/:id') 31 32 map.connect('*url', controller='template', action='view') trunk/MapFishSample/mapfishsample/controllers/cities.py
r414 r867 20 20 import logging 21 21 22 from sqlalchemy.sql import and_23 24 22 from mapfishsample.lib.base import * 25 23 26 from mapfish.pfpfeature import FeatureCollection 27 from mapfish.plugins.search import Search 28 29 import geojson 24 from mapfish.lib.filters import * 25 from mapfish.lib.protocol import Protocol, create_default_filter 30 26 31 27 log = logging.getLogger(__name__) 32 28 33 29 class CitiesController(BaseController): 30 readonly = True 34 31 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 20 20 import logging 21 21 22 from sqlalchemy.sql import and_23 24 22 from mapfishsample.lib.base import * 25 23 26 from mapfish.pfpfeature import FeatureCollection 27 from mapfish.plugins.search import Search 28 29 import geojson 24 from mapfish.lib.filters import * 25 from mapfish.lib.protocol import Protocol, create_default_filter 30 26 31 27 log = logging.getLogger(__name__) 32 28 33 29 class CountriesController(BaseController): 30 readonly = True 34 31 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 22 22 from mapfishsample.lib.base import * 23 23 from mapfish.plugins import pgrouting 24 from mapfish.pfpfeature import FeatureCollection25 24 26 import geojson 25 from geojson import FeatureCollection, dumps 27 26 28 27 log = logging.getLogger(__name__) … … 45 44 cost = "length::float8" 46 45 47 route = pgrouting.shortest_path(config['pylons.g'].sa_ routing_engine,46 route = pgrouting.shortest_path(config['pylons.g'].sa_mapfishsample_engine, 48 47 "SELECT gid AS id, node1_id::int4 AS source, node2_id::int4 AS target, %(cost)s AS cost FROM lines2"%{'cost': cost}, 49 48 int(source_id), int(target_id)).fetchall() … … 58 57 result = FeatureCollection([line.toFeature() for line in lines if line is not None and line.geom is not None]) 59 58 60 result. extend([source_f, target_f])59 result.features.extend([source_f, target_f]) 61 60 #length = sum([line.length for line in lines if line is not None]) 62 61 63 return geojson.dumps(result)62 return dumps(result) 64 63 trunk/MapFishSample/mapfishsample/model/__init__.py
r452 r867 26 26 27 27 from mapfish.sqlalchemygeom import Geometry 28 from mapfish. pfpfeature import Feature28 from mapfish.sqlalchemygeom import GeometryTableMixIn 29 29 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)} 30 from geojson import Feature 36 31 37 Session = scoped_session(sessionmaker(transactional=True, autoflush=True , binds=binds))32 Session = scoped_session(sessionmaker(transactional=True, autoflush=True)) 38 33 39 34 ## routing 40 nodes_table = Table('nodes2', MetaData(config['pylons.g'].sa_ routing_engine),35 nodes_table = Table('nodes2', MetaData(config['pylons.g'].sa_mapfishsample_engine), 41 36 Column('node_id', types.Integer, primary_key=True), 42 37 Column('room', types.String, unique=True), … … 45 40 46 41 class Node(object): 42 __table__ = nodes_table 47 43 def toFeature(self): 48 44 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)}) 50 46 51 52 lines_table = Table('lines2', MetaData(config['pylons.g'].sa_routing_engine), 47 lines_table = Table('lines2', MetaData(config['pylons.g'].sa_mapfishsample_engine), 53 48 Column('gid', types.Integer, primary_key=True), 54 49 Column('length', types.Float), … … 58 53 def toFeature(self): 59 54 return Feature(id=int(self.gid), geometry=self.geom, 60 distance=float(self.length))55 properties={'distance': float(self.length)}) 61 56 62 57 mapper(Node, nodes_table) 63 58 mapper(Line, lines_table) 64 59 65 ## c2c org66 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.name75 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 83 60 ## world_factbk 84 countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_ geostat_engine),61 countries_table = Table('world_factbk_simplified', MetaData(config['pylons.g'].sa_mapfishsample_engine), 85 62 Column('gid', types.Integer, primary_key=True), 86 63 Column('country', types.String), … … 90 67 Column('simplify', Geometry)) 91 68 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) 69 class Country(GeometryTableMixIn): 70 __table__ = countries_table 100 71 101 72 mapper(Country, countries_table) 102 73 103 74 ## world_cities 104 cities_table = Table('world_cities', MetaData(config['pylons.g'].sa_ geostat_engine),75 cities_table = Table('world_cities', MetaData(config['pylons.g'].sa_mapfishsample_engine), 105 76 Column('id', types.Integer, primary_key=True), 106 77 Column('ufi', types.Integer), … … 112 83 Column('the_geom', Geometry(4326))) 113 84 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) 85 class City(GeometryTableMixIn): 86 __table__ = cities_table 122 87 123 88 mapper(City, cities_table) trunk/MapFishSample/mapfishsample/public/demos/c2corg/search.html
r687 r867 413 413 'searchTolerance': 4 414 414 }, { 415 'url': '../../ c2corg',415 'url': '../../summits', 416 416 'params': { 417 417 'maxfeatures': 10 … … 423 423 424 424 var mediator = new mapfish.SearchMediator( 425 '../../ c2corg',425 '../../summits', 426 426 function(features) { 427 427 featureStore.removeAll(); trunk/mapfishsample/configs/aravis.wrk.cby.camptocamp.com
r736 r867 1 1 export DEBUG="true" 2 2 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 3 export DB_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/mapfishsample 6 4 7 5 export MVN="/home/elemoine/soft/apache-maven-2.0.8/bin/mvn" trunk/mapfishsample/configs/defaults
r737 r867