Exemple #1
0
 def select(self):
     data = self.cleaned_data
     bbox = data['bbox']
     geom_wkt = bbox.ewkt
     coord_srid = bbox.srid
     original_srid = self.queryset.geo_field.srid
     try:
         tolerance = self.tolerances[data['z']]
     except IndexError:
         tolerance = self.tolerances[-1]
     attrname = query.geo_field(self.queryset).name
     self.queryset = query.filter_geometry(self.queryset,
                                           intersects=geom_wkt)
     if data['clip']:
         self.queryset = self.queryset.intersection(geom_wkt)
         attrname = 'intersection'
     for obj in self.queryset:
         geom = getattr(obj, attrname)
         # Geometry must be in Web Mercator for simplification.
         if geom.srid != self.tile_srid:
             # Result of intersection does not have SRID set properly.
             if geom.srid is None:
                 geom.srid = original_srid
             geom.transform(self.tile_srid)
         geom = geom.simplify(tolerance, preserve_topology=True)
         geom.transform(coord_srid)
         obj.geojson = geom.geojson
Exemple #2
0
 def __init__(self, queryset, style=None):
     table = str(queryset.model._meta.db_table)
     field = query.geo_field(queryset)
     sref = srs.SpatialReference(query.get_srid(queryset))
     layer = mapnik.Layer(table, sref.proj4)
     layer.datasource = make_dbsource(
         table=table, geometry_field=field.name)
     self._layer = layer
     self.stylename = style or self._layer.name
     self._symbolizer = None
Exemple #3
0
 def __init__(self, queryset):
     table = str(queryset.model._meta.db_table)
     field = query.geo_field(queryset)
     sref = srs.SpatialReference(query.get_srid(queryset))
     layer = mapnik.Layer(table, sref.proj4)
     layer.datasource = make_dbsource(
         table=table, geometry_field=field.name)
     self._layer = layer
     self.stylename = self._layer.name
     self._symbolizer = None
Exemple #4
0
 def __init__(self, queryset, style=None):
     table = str(queryset.model._meta.db_table)
     field = query.geo_field(queryset)
     sref = srs.SpatialReference(query.get_srid(queryset))
     layer = mapnik.Layer(table, sref.proj4)
     ds = make_dbsource(table=table, geometry_field=field.name)
     # During tests, the spatialite layer statistics are not updated and
     # return an invalid layer extent. Set it from the queryset.
     if not ds.envelope().valid():
         ex = ','.join(map(str, queryset.extent()))
         ds = make_dbsource(table=table, geometry_field=field.name,
                            extent=ex)
     layer.datasource = ds
     self._layer = layer
     self.stylename = style or self._layer.name
     self._symbolizer = None
Exemple #5
0
 def __init__(self, queryset, style=None):
     table = str(queryset.model._meta.db_table)
     field = query.geo_field(queryset)
     sref = srs.SpatialReference(query.get_srid(queryset))
     layer = mapnik.Layer(table, sref.proj4)
     ds = make_dbsource(table=table, geometry_field=field.name)
     # During tests, the spatialite layer statistics are not updated and
     # return an invalid layer extent. Set it from the queryset.
     if not ds.envelope().valid():
         ex = ','.join(map(str, queryset.extent()))
         ds = make_dbsource(table=table,
                            geometry_field=field.name,
                            extent=ex)
     layer.datasource = ds
     self._layer = layer
     self.stylename = style or self._layer.name
     self._symbolizer = None
Exemple #6
0
 def select(self):
     kwargs = {}
     data = self.cleaned_data
     tolerance, srs, format = map(data.get, ('simplify', 'srs', 'format'))
     expr = field = query.geo_field(self.queryset).name
     srid = getattr(srs, 'srid', None)
     if srid:
         expr = functions.Transform(expr, srid)
     if data['op']:
         expr = data['op'](expr)
     if data['precision'] is not None:
         kwargs.update(precision=data['precision'])
     if tolerance:
         expr = query.Simplify(expr, tolerance)
     if format:
         expr = format(expr, **kwargs)
     if expr != field:
         attrname = self.data.get('format')
         self.queryset = self.queryset.annotate(**{attrname: expr})
Exemple #7
0
 def select(self):
     kwargs = {}
     data = self.cleaned_data
     tolerance, srs, format = map(data.get, ('simplify', 'srs', 'format'))
     expr = field = query.geo_field(self.queryset).name
     srid = getattr(srs, 'srid', None)
     if srid:
         expr = functions.Transform(expr, srid)
     if data['op']:
         expr = data['op'](expr)
     if data['precision'] is not None:
         kwargs.update(precision=data['precision'])
     if tolerance:
         expr = query.Simplify(expr, tolerance)
     if format:
         expr = format(expr, **kwargs)
     if expr != field:
         attrname = self.data.get('format')
         self.queryset = self.queryset.annotate(**{attrname: expr})