def select(self, action):
     obj_list = []    
     max_features = action.maxfeatures or 1000
     if action.id:
         obj = self.model.get_by_id(action.id)
         if obj:
             obj_list = [obj]
     else:
         obj_list = self.model.all()
         if action.attributes:
             current_key = None
             for key, value in action.attributes.items():
                 if isinstance(value, dict):
                     obj_list = obj_list.filter("%s %s" % (value['column'], self.query_action_string[value['type']]), value['value'])
                 else:
                     try: value = int(value)
                     except: pass
                     obj_list = obj_list.filter("%s =" % key, value)
                     
                     
         if action.bbox: 
             #geocell likes N,E,S,W bbox with 
             W,S,E,N = action.bbox
             #also needs to be valid wgs84 coords
             W = max(W, -180)
             E = min(E, 180)
             S = max(S, -90)
             N = min(N, 90)
             obj_list = self.model.bounding_box_fetch(
                 obj_list, 
                 geotypes.Box(N,E,S,W),
                 max_results=max_features)
                 
     return_list = []
     for obj in obj_list[:max_features]:
         props = {}
         #get attribs for model
         for key in self.model.fields():
             if not key in self.excluded_fields:
                 try: props[key] = getattr(obj, key)
                 except: props[key] = None
         #get additional attribs for expando stuff
         for key in obj.dynamic_properties():
                 try: props[key] = getattr(obj, key)
                 except: props[key] = None
         try: geom = from_wkt(obj.geometry)
         except: 
             logging.error('fail on obj %s' % key)
             continue
         return_list.append(Feature(id=action.id, geometry=from_wkt(obj.geometry), srs=self.srid_out, props=props))
     return return_list    
예제 #2
0
    def select(self, action):
        obj_list = []
        if action.id:
            obj = self.model.get_by_id(action.id)
            if obj:
                obj_list = [obj]
        else:
            obj_list = self.model.all()
            if action.bbox:
                if geohash_support:
                    bbox = action.bbox
                    hash1 = Geoindex(bbox[0:2])
                    hash2 = Geoindex(bbox[2:])
                    obj_list = obj_list.filter("geohash <=", str(hash2)).filter("geohash >=", str(hash1))
                else:
                    raise Exception("No GeoHash support -> No bbox support.")

            if action.attributes:
                current_key = None
                for key, value in action.attributes.items():
                    if isinstance(value, dict):
                        obj_list.filter("%s %s" % (key, self.query_action_string[value["type"]]), value["value"])
                    else:
                        obj_list.filter("%s =" % key, value)
        return_list = []
        for obj in obj_list:
            props = {}
            for key in obj.dynamic_properties():
                props[key] = getattr(obj, key)
            return_list.append(Feature(obj.key().id(), from_wkt(obj.geometry), props))
        return return_list
예제 #3
0
    def select(self, action):
        obj_list = []
        if action.id:
            obj = self.model.get_by_id(action.id)
            if obj:
                obj_list = [obj]
        else:
            obj_list = self.model.all()
            if action.bbox:
                if geohash_support:
                    bbox = action.bbox
                    hash1 = Geoindex(bbox[0:2])
                    hash2 = Geoindex(bbox[2:])
                    obj_list = obj_list.filter("geohash <=",
                                               str(hash2)).filter(
                                                   "geohash >=", str(hash1))
                else:
                    raise Exception("No GeoHash support -> No bbox support.")

            if action.attributes:
                current_key = None
                for key, value in action.attributes.items():
                    if isinstance(value, dict):
                        obj_list.filter(
                            "%s %s" %
                            (value['column'],
                             self.query_action_string[value['type']]),
                            value['value'])
                    else:
                        obj_list.filter("%s =" % key, value)
        return_list = []
        for obj in obj_list:
            props = {}
            for key in obj.dynamic_properties():
                props[key] = getattr(obj, key)
            return_list.append(
                Feature(id=obj.key().id(),
                        geometry=from_wkt(obj.geometry),
                        srs=self.srid_out,
                        props=props))
        return return_list
예제 #4
0
    def select(self, action):
        obj_list = []
        max_features = action.maxfeatures or 1000
        if action.id:
            obj = self.model.get_by_id(action.id)
            if obj:
                obj_list = [obj]
        else:
            obj_list = self.model.all()
            if action.attributes:
                current_key = None
                for key, value in action.attributes.items():
                    if isinstance(value, dict):
                        obj_list = obj_list.filter(
                            "%s %s" %
                            (value['column'],
                             self.query_action_string[value['type']]),
                            value['value'])
                    else:
                        try:
                            value = int(value)
                        except:
                            pass
                        obj_list = obj_list.filter("%s =" % key, value)

            if action.bbox:
                #geocell likes N,E,S,W bbox with
                W, S, E, N = action.bbox
                #also needs to be valid wgs84 coords
                W = max(W, -180)
                E = min(E, 180)
                S = max(S, -90)
                N = min(N, 90)
                obj_list = self.model.bounding_box_fetch(
                    obj_list,
                    geotypes.Box(N, E, S, W),
                    max_results=max_features)

        return_list = []
        for obj in obj_list[:max_features]:
            props = {}
            #get attribs for model
            for key in self.model.fields():
                if not key in self.excluded_fields:
                    try:
                        props[key] = getattr(obj, key)
                    except:
                        props[key] = None
            #get additional attribs for expando stuff
            for key in obj.dynamic_properties():
                try:
                    props[key] = getattr(obj, key)
                except:
                    props[key] = None
            try:
                geom = from_wkt(obj.geometry)
            except:
                logging.error('fail on obj %s' % key)
                continue
            return_list.append(
                Feature(id=action.id,
                        geometry=from_wkt(obj.geometry),
                        srs=self.srid_out,
                        props=props))
        return return_list