def test_simplify_geojson(self): fn = functions.AsGeoJSON(query.Simplify( functions.Transform('geom', self.srid), self.tol), precision=2) sqs = self.qs.all().annotate(geojson=fn) geom = geos.GEOSGeometry(sqs[0].geojson, self.srid) source = self.qs[0].geom self.assertNotEqual(geom, source) self.assertNotEqual(geom.srid, source.srid) self.assertLess(geom.num_coords, source.num_coords)
def test_serialize_queryset_simplify(self): fn = query.Simplify(functions.Transform('geom', 4269), 1.01) qs = Location.objects.all() for obj in qs: obj.geom = obj.geom.buffer(1.5) obj.save() qs = qs.annotate(simplify=fn) obj = qs[0] serializer = SimplifyLocationSerializer(obj) g = geos.GEOSGeometry(json.dumps(serializer.data['geometry']), srid=obj.simplify.srid) self.assertEqual(g, obj.simplify) self.assertEqual(obj.simplify.srid, 4269) self.assertEqual(serializer.data['crs']['properties']['name'][-4:], '4269')
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})
def test_simplify_kml(self): fn = functions.AsKML(query.Simplify('geom', self.radius)) sqs = self.qs.all().annotate(kml=fn) self.assertTrue(sqs[0].kml.startswith('<Polygon>')) self.assertNotIn('<coordinates></coordinates>', sqs[0].kml) self.assertXMLNotEqual(sqs[0].kml, self.qs[0].geom.kml)