Exemplo n.º 1
0
    def _handle_spatial_filters(self, coll, api_arguments, q):
        # handle geospatial queries
        if 'geo' in api_arguments:
            print("Geospatial limit")
            geo = json.loads(
                api_arguments['geo']) \
                    if isinstance(api_arguments['geo'], str) \
                    else api_arguments['geo']

            geometries = [k for k in coll.document_class.specials if coll.document_class.specials[k].is_geometry]

            if not geometries:
                raise ValidationError("Requested a geometric query on a non geometric collection")
            if 'against' not in geo:
                test_property = geometries[0]
            elif geo['against'] not in geometries:
                raise KeyError('Not a valid geometry name')
            else:
                test_property = geo['against']
            op = geo['op']
            geom = r.geojson(geo['test'])
            if op not in self.GEOSPATIAL_OPS:
                raise ValidationError("Cannot perform non geometry op in geometry query")
            q = getattr(q, op)(geom, index=test_property, *geo.get('args',[]), **geo.get('kwargs', {}))
        return q
Exemplo n.º 2
0
    def _handle_spatial_filters(self, coll, api_arguments, q):
        # handle geospatial queries
        if 'geo' in api_arguments:
            print("Geospatial limit")
            geo = json.loads(
                api_arguments['geo']) \
                    if isinstance(api_arguments['geo'], str) \
                    else api_arguments['geo']

            geometries = [
                k for k in coll.document_class.specials
                if coll.document_class.specials[k].is_geometry
            ]

            if not geometries:
                raise ValidationError(
                    "Requested a geometric query on a non geometric collection"
                )
            if 'against' not in geo:
                test_property = geometries[0]
            elif geo['against'] not in geometries:
                raise KeyError('Not a valid geometry name')
            else:
                test_property = geo['against']
            op = geo['op']
            geom = r.geojson(geo['test'])
            if op not in self.GEOSPATIAL_OPS:
                raise ValidationError(
                    "Cannot perform non geometry op in geometry query")
            q = getattr(q, op)(geom,
                               index=test_property,
                               *geo.get('args', []),
                               **geo.get('kwargs', {}))
        return q
Exemplo n.º 3
0
def insert_location(connection, dstTable, rec):
    res = r.db(NEWDB).table(dstTable).insert(
        {
            'name': rec['name'],
            'location': r.geojson(rec['location'])
        },
        return_changes=True).run(connection)
    return res['changes'][0]['new_val']['id']
Exemplo n.º 4
0
    def to_rql_repr(self, value, document):
        if value is None:
            return value
        if value == {}:
            return None

        if self.allowed_types:
            if value['type'].lower() not in self.allowed_types:
                raise ValidationError('value not in ' + ','.join(t for t in self.allowed_types))
        return r.geojson(value)
Exemplo n.º 5
0
 def to_rql_repr(self, value):
     if self.allowed_types:
         if value['type'].lower() not in self.allowed_types:
             raise ValidationError('value not in ' + ','.join(t for t in self.allowed_types))
     return r.geojson(value)
Exemplo n.º 6
0
db = r.db("engine")
db_lamps = db.table('lamps')
c = r.connect(host="localhost")

setup_db()
try:
    db_lamps.index_create('location', geo=True).run(c)
except r.RqlRuntimeError:
    logging.warn('Index already exists.')

location = {
    "type": "Point",
            "coordinates": [125.6, 10.1]
}

geo_position = r.geojson(location)

location2 = {
    "type": "Point",
            "coordinates": [15.6, 10.1]
}

geo_position2 = r.geojson(location2)

lamp = {
    "identifier": "Lamp Test",
    "group": [],
    "hardware": {
        "protocol": "madli",
                    "building": "stn",
                    "is_sensor": "false",