本文整理汇总了Python中mapfish.protocol.Protocol类的典型用法代码示例。如果您正苦于以下问题:Python Protocol类的具体用法?Python Protocol怎么用?Python Protocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Protocol类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_protocol_create_and_update
def test_protocol_create_and_update(self):
"""Create a new point and also update an already existing point"""
old_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [\
{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\
{"type": "Feature", "id": ' + str(old_spot.spot_id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}'
response = FakeResponse()
collection = proto.create(request, response)
eq_(response.status, 201)
eq_(len(collection.features), 2)
feature0 = collection.features[0]
eq_(feature0.id, 10)
eq_(feature0.geometry.coordinates, (45.0, 5.0))
eq_(feature0.properties["spot_height"], 12)
feature1 = collection.features[1]
eq_(feature1.id, old_spot.spot_id)
eq_(feature1.geometry.coordinates, (1, 1))
new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
ok_(new_spot is not None)
eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')
updated_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
ok_(updated_spot is not None)
ok_(old_spot is updated_spot)
eq_(updated_spot.spot_height, 102.34)
eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')
开发者ID:123rohan123,项目名称:mapfish,代码行数:33,代码来源:test_postgis.py
示例2: test_protocol_count_filter_box
def test_protocol_count_filter_box(self):
"""Get the feature count with a box as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['bbox'] = '-10,-10,10,10'
eq_(proto.count(request), '4')
request.params['tolerance'] = '200000'
eq_(proto.count(request), '5')
# query features that are inside a bbox that uses a different CRS
# note that we either have to specify a tolerance ('tol') or
# dimension information ('dim1' and 'dim2')
filter = create_default_filter(request, Spot, additional_params={'tol': '0.005'})
request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951'
request.params['epsg'] = '2210'
request.params['tolerance'] = '0'
eq_(proto.count(request, filter=filter), '5')
# dimension information array for 54004
# see http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11830/sdo_objrelschema.htm#i1010905
diminfo = "MDSYS.SDO_DIM_ARRAY("\
"MDSYS.SDO_DIM_ELEMENT('LONGITUDE', -20037508, 20037508, 0.005),"\
"MDSYS.SDO_DIM_ELEMENT('LATITUDE', -19929239, 19929239, 0.005)"\
")"
request.params['bbox'] = '-975862.822682856,-999308.345117013,1027887.98627823,999373.702609189'
request.params['epsg'] = '54004' # Oracles SRID number for World Mercator
filter = create_default_filter(request, Spot,
additional_params={'dim1': text(diminfo),
'dim2' : text(diminfo)})
eq_(proto.count(request, filter=filter), '3')
开发者ID:123rohan123,项目名称:mapfish,代码行数:33,代码来源:test_oracle.py
示例3: test_protocol_create_fails
def test_protocol_create_fails(self):
"""Try to create a feature without geometry"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}'
proto.create(request, FakeResponse())
开发者ID:123rohan123,项目名称:mapfish,代码行数:8,代码来源:test_postgis.py
示例4: test_protocol_count_queryable
def test_protocol_count_queryable(self):
"""Count all features that match a filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['queryable'] = 'spot_height'
request.params['spot_height__gte'] = '1454.66'
eq_(proto.count(request), '3')
开发者ID:123rohan123,项目名称:mapfish,代码行数:8,代码来源:test_postgis.py
示例5: test_protocol_read_all
def test_protocol_read_all(self):
"""Return all features"""
proto = Protocol(session, Spot)
collection = proto.read(FakeRequest({}))
ok_(collection is not None)
ok_(isinstance(collection, FeatureCollection))
eq_(len(collection.features), 9)
开发者ID:123rohan123,项目名称:mapfish,代码行数:8,代码来源:test_postgis.py
示例6: test_protocol_count_filter_geometry
def test_protocol_count_filter_geometry(self):
"""Get the feature count with a geometry as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['geometry'] = '{"type": "Polygon", "coordinates": [[ [-10, -1], [10, -1], [0, 10], [-10, -1] ]]}'
eq_(proto.count(request), '2')
request.params['tolerance'] = '10'
eq_(proto.count(request), '5')
开发者ID:123rohan123,项目名称:mapfish,代码行数:10,代码来源:test_postgis.py
示例7: test_protocol_read_one
def test_protocol_read_one(self):
"""Return one feature"""
proto = Protocol(session, Spot)
feature = proto.read(FakeRequest({}), id=1)
ok_(feature is not None)
ok_(isinstance(feature, Feature))
eq_(feature.id, 1)
eq_(feature.geometry.coordinates, (0.0, 0.0))
eq_(feature.properties["spot_height"], 420.39999999999998)
开发者ID:123rohan123,项目名称:mapfish,代码行数:10,代码来源:test_oracle.py
示例8: test_protocol_update_fails
def test_protocol_update_fails(self):
"""Try to update a not-existing feature"""
proto = Protocol(session, Spot)
id = -1
request = FakeRequest({})
request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
response = FakeResponse()
proto.update(request, response, id)
开发者ID:123rohan123,项目名称:mapfish,代码行数:10,代码来源:test_postgis.py
示例9: test_protocol_count_filter_box
def test_protocol_count_filter_box(self):
"""Get the feature count with a box as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['bbox'] = '-10,-10,10,10'
eq_(proto.count(request), '4')
request.params['tolerance'] = '1'
eq_(proto.count(request), '5')
开发者ID:123rohan123,项目名称:mapfish,代码行数:10,代码来源:test_mysql.py
示例10: test_protocol_count_filter_box_reproject
def test_protocol_count_filter_box_reproject(self):
"""Try to get the feature count with a box that has to be reprojected
(MySQL does not support transform() yet)"""
proto = Protocol(session, Spot)
request = FakeRequest({})
# reproject the bbox
request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951'
request.params['epsg'] = '4807'
request.params['tolerance'] = '0'
proto.count(request)
开发者ID:123rohan123,项目名称:mapfish,代码行数:11,代码来源:test_mysql.py
示例11: test_protocol_count_filter_within
def test_protocol_count_filter_within(self):
"""Get the feature count with a point as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['lat'] = '0'
request.params['lon'] = '0'
eq_(proto.count(request), '1')
request.params['tolerance'] = '10'
eq_(proto.count(request), '3')
开发者ID:123rohan123,项目名称:mapfish,代码行数:11,代码来源:test_postgis.py
示例12: ZonesController
class ZonesController(BaseController):
readonly = True # if set to True, only GET is supported
def __init__(self):
self.protocol = Protocol(Session, Zone, self.readonly)
@geojsonify
def index(self, format='json'):
"""GET /: return all features."""
# If no filter argument is passed to the protocol index method
# then the default MapFish filter is used.
#
# If you need your own filter with application-specific params
# taken into acount, create your own filter and pass it to the
# protocol read method.
#
# E.g.
#
# from sqlalchemy.sql import and_
#
# default_filter = create_default_filter(request, Zone)
# filter = and_(default_filter, Zone.columname.ilike('%value%'))
# return self.protocol.read(request, filter=filter)
if format != 'json':
abort(404)
return self.protocol.read(request)
@geojsonify
def show(self, id, format='json'):
"""GET /id: Show a specific feature."""
if format != 'json':
abort(404)
return self.protocol.read(request, response, id=id)
#@geojsonify
#def create(self):
# """POST /: Create a new feature."""
# return self.protocol.create(request, response)
#
#@geojsonify
#def update(self, id):
# """PUT /id: Update an existing feature."""
# return self.protocol.update(request, response, id)
#
#def delete(self, id):
# """DELETE /id: Delete an existing feature."""
# return self.protocol.delete(request, response, id)
def count(self):
"""GET /count: Count all features."""
return self.protocol.count(request)
开发者ID:gocodeboulder,项目名称:hotspots-mapfish,代码行数:53,代码来源:zones.py
示例13: test_protocol_read_one_null
def test_protocol_read_one_null(self):
"""Return one null feature"""
proto = Protocol(session, Spot)
feature = proto.read(FakeRequest({}), id=9)
ok_(feature is not None)
ok_(isinstance(feature, Feature))
eq_(feature.id, 9)
# make use of __geo_interface__ property since 'geometry'
# value is not the same in various versions of geojson lib
ok_(feature.__geo_interface__['geometry'] is None)
ok_(feature.__geo_interface__['bbox'] is None)
开发者ID:123rohan123,项目名称:mapfish,代码行数:12,代码来源:test_postgis.py
示例14: test_protocol_delete
def test_protocol_delete(self):
"""Delete an existing point"""
proto = Protocol(session, Spot)
id = 1
request = FakeRequest({})
response = FakeResponse()
proto.delete(request, response, id)
eq_(response.status, 204)
spot = session.query(Spot).get(id)
ok_(spot is None)
开发者ID:123rohan123,项目名称:mapfish,代码行数:13,代码来源:test_postgis.py
示例15: test_protocol_count_filter_within
def test_protocol_count_filter_within(self):
"""Get the feature count with a point as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['lat'] = '0'
request.params['lon'] = '0'
eq_(proto.count(request), '1')
request.params['tolerance'] = '400000'
eq_(proto.count(request), '2')
filter = create_default_filter(request, Spot, additional_params={'params': 'unit=KM'})
eq_(proto.count(request, filter=filter), '8')
开发者ID:123rohan123,项目名称:mapfish,代码行数:14,代码来源:test_oracle.py
示例16: test_protocol_create
def test_protocol_create(self):
from mapfish.protocol import Protocol
proto = Protocol(Session, MappedClass)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
response = FakeResponse()
proto.create(request, response, execute=False)
assert response.status == 201
assert len(Session.new) == 2
for obj in Session.new:
assert obj["text"] == "foo"
assert obj._mf_shape.x == 45
assert obj._mf_shape.y == 5
Session.rollback()
开发者ID:123rohan123,项目名称:mapfish,代码行数:14,代码来源:test_protocol.py
示例17: test_protocol_count_filter_box
def test_protocol_count_filter_box(self):
"""Get the feature count with a box as filter"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.params['bbox'] = '-10,-10,10,10'
eq_(proto.count(request), '4')
request.params['tolerance'] = '1'
eq_(proto.count(request), '5')
# reproject the bbox
request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951'
request.params['epsg'] = '4807'
request.params['tolerance'] = '0'
eq_(proto.count(request), '4')
开发者ID:123rohan123,项目名称:mapfish,代码行数:16,代码来源:test_postgis.py
示例18: test_protocol_query
def test_protocol_query(self):
from mapfish.protocol import Protocol, create_attr_filter
proto = Protocol(Session, MappedClass)
request = FakeRequest({})
query = proto._query(request, execute=False)
stmt = query.statement
stmtm_str = stmt.compile(engine)
assert "SELECT" in query_to_str(query)
request = FakeRequest({"queryable": "id", "id__eq": "1"})
query = proto._query(request, execute=False)
assert "WHERE" in query_to_str(query)
request = FakeRequest({"queryable": "id", "id__eq": "1"})
filter = create_attr_filter(request, MappedClass)
query = proto._query(FakeRequest({}), filter=filter, execute=False)
assert "WHERE" in query_to_str(query)
request = FakeRequest({"limit": "2"})
query = proto._query(request, execute=False)
print query_to_str(query)
assert "LIMIT" in query_to_str(query)
request = FakeRequest({"maxfeatures": "2"})
query = proto._query(request, execute=False)
assert "LIMIT" in query_to_str(query)
request = FakeRequest({"limit": "2", "offset": "10"})
query = proto._query(request, execute=False)
assert "OFFSET" in query_to_str(query)
request = FakeRequest({"order_by": "text"})
query = proto._query(request, execute=False)
assert "ORDER BY" in query_to_str(query)
assert "ASC" in query_to_str(query)
request = FakeRequest({"sort": "text"})
query = proto._query(request, execute=False)
assert "ORDER BY" in query_to_str(query)
assert "ASC" in query_to_str(query)
request = FakeRequest({"order_by": "text", "dir": "DESC"})
query = proto._query(request, execute=False)
assert "ORDER BY" in query_to_str(query)
assert "DESC" in query_to_str(query)
开发者ID:123rohan123,项目名称:mapfish,代码行数:46,代码来源:test_protocol.py
示例19: test_protocol_update
def test_protocol_update(self):
"""Update an existing point"""
proto = Protocol(session, Spot)
id = 1
request = FakeRequest({})
request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
response = FakeResponse()
feature = proto.update(request, response, id)
eq_(response.status, 201)
eq_(feature.id, 1)
eq_(feature.geometry.coordinates, (1.0, 1.0))
spot = session.query(Spot).get(id)
ok_(spot is not None)
eq_(session.scalar(spot.spot_location.wkt), u'POINT(1 1)')
开发者ID:123rohan123,项目名称:mapfish,代码行数:17,代码来源:test_postgis.py
示例20: test_protocol_create
def test_protocol_create(self):
"""Create a new point"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
response = FakeResponse()
collection = proto.create(request, response)
eq_(response.status, 201)
eq_(len(collection.features), 1)
feature0 = collection.features[0]
eq_(feature0.id, 10)
eq_(feature0.geometry.coordinates, (45.0, 5.0))
eq_(feature0.properties["spot_height"], 12)
new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
ok_(new_spot is not None)
eq_(session.scalar(new_spot.spot_location.wkt), u'POINT (45.0 5.0)')
开发者ID:123rohan123,项目名称:mapfish,代码行数:19,代码来源:test_oracle.py
注:本文中的mapfish.protocol.Protocol类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论