def get_queryset(self): #split params by which it applies to mappoint_params = {} for (param, result) in self.request.QUERY_PARAMS.items(): if param in ['max_lat','min_lat','max_lon','min_lon','dataset','tags','tag','state','zipcode']: mappoint_params[param] = result #if none of this is specified, this is just too much if len(mappoint_params) == 0: raise ParseError('Too many results. Please restrict the mappoints.') #now get the queryset points = filter_request(mappoint_params,'mappoint') distances = self.request.GET.getlist('distance') unit = self.request.GET.getlist('unit') if len(unit) > 1: raise ParseError('No more than one unit may be specified.') elif len(unit) == 0: unit = 'mi' elif unit[0] in ['m','km','mi']: unit = unit[0] else: raise ParseError('Accepted units: m, km, mi') if len(distances) == 0: distances = [1,3,5] unit = 'km' else: print distances distances.sort() kwargs = {unit:distances[-1]} take_out = [] for point in points: if point.id in take_out: continue take_out.extend(neighboring_points(point, points, Distance(**kwargs)).exclude(id=point.id).values_list('id',flat=True)) return points.exclude(id__in=take_out).distinct()
def get_queryset(self): #split params by which it applies to mappoint_params = {} for (param, result) in self.request.query_params.items(): if param in ['max_lat','min_lat','max_lon','min_lon','dataset','tags','tag','state','zipcode']: mappoint_params[param] = result #if none of this is specified, this is just too much if len(mappoint_params) == 0: raise ParseError('Too many results. Please restrict the mappoints.') #now get the queryset points = filter_request(mappoint_params,'mappoint') distances = self.request.GET.getlist('distance') unit = self.request.GET.getlist('unit') if len(unit) > 1: raise ParseError('No more than one unit may be specified.') elif len(unit) == 0: unit = 'mi' elif unit[0] in ['m','km','mi']: unit = unit[0] else: raise ParseError('Accepted units: m, km, mi') if len(distances) == 0: distances = [1,3,5] unit = 'km' else: print distances distances.sort() kwargs = {unit:distances[-1]} take_out = [] for point in points: if point.id in take_out: continue take_out.extend(neighboring_points(point, points, Distance(**kwargs)).exclude(id=point.id).values_list('id',flat=True)) return points.exclude(id__in=take_out).distinct()
def get_queryset(self, format=None): # split params by which it applies to mappolygon_params = {} for (param, result) in self.request.query_params.items(): if param in ['max_lat', 'min_lat', 'max_lon', 'min_lon']: mappolygon_params[param] = result elif param == 'poly_dataset': mappolygon_params['dataset'] = result # now get the querysets polygons = filter_request(mappolygon_params, 'mappolygon') if 'state' in self.request.query_params: polygons = polygons.filter(remote_id__startswith=self.request.query_params['state']) return polygons
def get_queryset(self, format=None): use_csv = format and format == 'csv' #split params by which it applies to mappolygon_params = {} for (param, result) in self.request.query_params.items(): if param in ['max_lat','min_lat','max_lon','min_lon']: mappolygon_params[param] = result elif param == 'poly_dataset': mappolygon_params['dataset'] = result #now get the querysets polygons = filter_request(mappolygon_params,'mappolygon') if 'state' in self.request.query_params: polygons = polygons.filter(remote_id__startswith=self.request.query_params['state']) return polygons if False: csv_response = HttpResponse(content_type='text/csv') filename = 'census_tract_stats' for t in tags: filename = filename + '_' + t csv_response['Content-Disposition'] = 'attachment; filename="' + filename + '.csv"' writer = csv.writer(csv_response) firstrow = ['polygon_id', polygons[0].dataset.field1_en, polygons[0].dataset.field2_en] for tag in tags: try: num = int(tag) t = Tag.objects.get(pk = num) t = t.tag except: t = tag firstrow.append(t + " count") if mult_tags: if not matchall: firstrow.append(all_tags + " count (match any)") firstrow.append(all_tags + " count (match all)") for df in datafields: firstrow.append(df.field_en) writer.writerow(firstrow) for poly in polygons: row = [poly.remote_id, poly.field1, poly.field2] #counts in polygons all_tag_filter = points if not matchall: for tag in tags: try: num = int(tag) temp = points.filter(tagindiv__tag=num) all_tag_filter = points.filter(tagindiv__tag=num) except: temp = points.filter(tagindiv__tag__tag=tag) all_tag_filter = points.filter(tagindiv__tag__tag=tag) row.append(temp.filter(point__intersects = poly.mpoly).count()) print points.filter(point__intersects = poly.mpoly).query if mult_tags: row.append(points.filter(point__intersects = poly.mpoly).count()) if mult_tags: row.append(all_tag_filter.filter(point__intersects = poly.mpoly).count()) #get other data for df in datafields: data = None if df.field_type == DataField.INTEGER: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].int_data elif df.field_type == DataField.FLOAT: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].float_data else: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].char_data if data: row.append(data) else: row.append('') writer.writerow(row) return csv_response
def get_queryset(self): return filter_request(self.request.query_params, 'mappolygon')
def get_queryset(self): return filter_request(self.request.query_params, 'mapelement')
def get_queryset(self, format=None): use_csv = format and format == 'csv' #split params by which it applies to mappolygon_params = {} for (param, result) in self.request.QUERY_PARAMS.items(): if param in ['max_lat','min_lat','max_lon','min_lon']: mappolygon_params[param] = result elif param == 'poly_dataset': mappolygon_params['dataset'] = result #now get the querysets polygons = filter_request(mappolygon_params,'mappolygon') if 'state' in self.request.QUERY_PARAMS: polygons = polygons.filter(remote_id__startswith=self.request.QUERY_PARAMS['state']) return polygons if False: csv_response = HttpResponse(content_type='text/csv') filename = 'census_tract_stats' for t in tags: filename = filename + '_' + t csv_response['Content-Disposition'] = 'attachment; filename="' + filename + '.csv"' writer = csv.writer(csv_response) firstrow = ['polygon_id', polygons[0].dataset.field1_en, polygons[0].dataset.field2_en] for tag in tags: try: num = int(tag) t = Tag.objects.get(pk = num) t = t.tag except: t = tag firstrow.append(t + " count") if mult_tags: if not matchall: firstrow.append(all_tags + " count (match any)") firstrow.append(all_tags + " count (match all)") for df in datafields: firstrow.append(df.field_en) writer.writerow(firstrow) for poly in polygons: row = [poly.remote_id, poly.field1, poly.field2] #counts in polygons all_tag_filter = points if not matchall: for tag in tags: try: num = int(tag) temp = points.filter(tagindiv__tag=num) all_tag_filter = points.filter(tagindiv__tag=num) except: temp = points.filter(tagindiv__tag__tag=tag) all_tag_filter = points.filter(tagindiv__tag__tag=tag) row.append(temp.filter(point__intersects = poly.mpoly).count()) print points.filter(point__intersects = poly.mpoly).query if mult_tags: row.append(points.filter(point__intersects = poly.mpoly).count()) if mult_tags: row.append(all_tag_filter.filter(point__intersects = poly.mpoly).count()) #get other data for df in datafields: data = None if df.field_type == DataField.INTEGER: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].int_data elif df.field_type == DataField.FLOAT: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].float_data else: element = DataElement.objects.filter(datafield = df).filter(mapelement=poly) if element: data = element[0].char_data if data: row.append(data) else: row.append('') writer.writerow(row) return csv_response
def get_queryset(self): return filter_request(self.request.QUERY_PARAMS, 'mappolygon')
def get_queryset(self): return filter_request(self.request.QUERY_PARAMS, 'mapelement')
def get_count(self, mappolygon): request = self.context.get('request', None) params = copy.deepcopy(request.query_params) for key in ['max_lat', 'min_lat', 'max_lon', 'min_lon', 'state']: try: del params[key] except Exception: pass # no big deal c = {mappolygon.dataset.names.field1_en: mappolygon.mappolygon.field1, mappolygon.dataset.names.field2_en: mappolygon.mappolygon.field2} datafields = DataField.objects.filter(dataset=mappolygon.dataset) # get other data for df in datafields: data = None if df.field_type == DataField.INTEGER: element = DataElement.objects.filter(datafield=df) \ .filter(mapelement=mappolygon) if element: data = element[0].int_data elif df.field_type == DataField.FLOAT: element = DataElement.objects.filter(datafield=df) \ .filter(mapelement=mappolygon) if element: data = element[0].float_data else: element = DataElement.objects.filter(datafield=df) \ .filter(mapelement=mappolygon) if element: data = element[0].char_data if data: c[df.field_en] = data points = filter_request(params, 'mappoint').filter(point__intersects=mappolygon.mappolygon.mpoly) all_tags = None if 'tag' in params: all_tags = params['tag'] elif 'tags' in params: all_tags = params['tags'] if all_tags: tags = all_tags.split(',') if type(tags) is not list: tags = [tags] all_tags = all_tags.replace(',', ', ') else: tags = [] # counts in polygons if 'match' not in params or params['match'] != 'all': all_tag_filter = points for tag in tags: try: num = int(tag) tag_obj = Tag.objects.get(num) all_tag_filter = all_tag_filter.filter(tagindiv__tag=tag_obj) c[tag_obj.tag + " count"] = points.filter(tagindiv__tag=tag_obj).count() except Exception: all_tag_filter = all_tag_filter.filter(tagindiv__tag__tag=tag) c[tag + " count"] = points.filter(tagindiv__tag__tag=tag).count() if len(tags) > 1: c[all_tags + " count (match any)"] = points.count() c[all_tags + " count (match all)"] = points.count() if len(tags) > 1: c[all_tags + " count (match all)"] = points.count() return c
def get_queryset(self): return filter_request(self.request.query_params, 'mappolygon')
def get_queryset(self): return filter_request(self.request.query_params, 'mapelement')