当前位置: 首页>>代码示例>>Python>>正文


Python functions.Transform方法代码示例

本文整理汇总了Python中django.contrib.gis.db.models.functions.Transform方法的典型用法代码示例。如果您正苦于以下问题:Python functions.Transform方法的具体用法?Python functions.Transform怎么用?Python functions.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.gis.db.models.functions的用法示例。


在下文中一共展示了functions.Transform方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: select

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
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}) 
开发者ID:bkg,项目名称:django-spillway,代码行数:21,代码来源:forms.py

示例2: calculate_area_field

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def calculate_area_field(apps, schema_editor):
    SpatialUnit = apps.get_model('spatial', 'SpatialUnit')
    SpatialUnit.objects.exclude(geometry=None).extra(
        where=["geometrytype(geometry) LIKE 'POLYGON'"]).update(
        area=Area(Transform('geometry', 3857))) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:0004_area_location_field.py

示例3: extent

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def extent(self, srid=None):
        """Returns the GeoQuerySet extent as a 4-tuple.

        Keyword args:
        srid -- EPSG id for for transforming the output geometry.
        """
        expr = self.geo_field.name
        if srid:
            expr = geofn.Transform(expr, srid)
        expr = models.Extent(expr)
        clone = self.all()
        name, val = clone.aggregate(expr).popitem()
        return val 
开发者ID:bkg,项目名称:django-spillway,代码行数:15,代码来源:query.py

示例4: tile

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def tile(self, bbox, z=0, format=None, clip=True):
        """Returns a GeoQuerySet intersecting a tile boundary.

        Arguments:
        bbox -- tile extent as geometry
        Keyword args:
        z -- tile zoom level used as basis for geometry simplification
        format -- vector tile format as str (pbf, geojson)
        clip -- clip geometries to tile boundary as boolean
        """
        # Tile grid uses 3857, but GeoJSON coordinates should be in 4326.
        tile_srid = 3857
        bbox = getattr(bbox, 'geos', bbox)
        clone = filter_geometry(self, intersects=bbox)
        field = clone.geo_field
        srid = field.srid
        sql = field.name
        try:
            tilew = self.tilewidths[z]
        except IndexError:
            tilew = self.tilewidths[-1]
        if bbox.srid != srid:
            bbox = bbox.transform(srid, clone=True)
        # Estimate tile width in degrees instead of meters.
        if bbox.srs.geographic:
            p = geos.Point(tilew, tilew, srid=tile_srid)
            p.transform(srid)
            tilew = p.x
        if clip:
            bufbox = bbox.buffer(tilew)
            sql = geofn.Intersection(sql, bufbox.envelope)
        sql = SimplifyPreserveTopology(sql, tilew)
        if format == 'pbf':
            return clone.pbf(bbox, geo_col=sql)
        sql = geofn.Transform(sql, 4326)
        return clone.annotate(**{format: sql}) 
开发者ID:bkg,项目名称:django-spillway,代码行数:38,代码来源:query.py

示例5: test_serialize_queryset_simplify

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
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') 
开发者ID:bkg,项目名称:django-spillway,代码行数:16,代码来源:test_serializers.py

示例6: test_simplify_geojson

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
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) 
开发者ID:bkg,项目名称:django-spillway,代码行数:12,代码来源:test_query.py

示例7: test_inherited_geofields

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def test_inherited_geofields(self):
        "Database functions on inherited Geometry fields."
        # Creating a Pennsylvanian city.
        PennsylvaniaCity.objects.create(name='Mansfield', county='Tioga', point='POINT(-77.071445 41.823881)')

        # All transformation SQL will need to be performed on the
        # _parent_ table.
        qs = PennsylvaniaCity.objects.annotate(new_point=functions.Transform('point', srid=32128))

        self.assertEqual(1, qs.count())
        for pc in qs:
            self.assertEqual(32128, pc.new_point.srid) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例8: test_transform

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def test_transform(self):
        # Pre-transformed points for Houston and Pueblo.
        ptown = fromstr('POINT(992363.390841912 481455.395105533)', srid=2774)
        prec = 3  # Precision is low due to version variations in PROJ and GDAL.

        # Asserting the result of the transform operation with the values in
        #  the pre-transformed points.
        h = City.objects.annotate(pt=functions.Transform('point', ptown.srid)).get(name='Pueblo')
        self.assertEqual(2774, h.pt.srid)
        self.assertAlmostEqual(ptown.x, h.pt.x, prec)
        self.assertAlmostEqual(ptown.y, h.pt.y, prec) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:test_functions.py

示例9: kml

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
    """
    This view generates KML for the given app label, model, and field name.

    The field name must be that of a geographic field.
    """
    placemarks = []
    try:
        klass = apps.get_model(label, model)
    except LookupError:
        raise Http404('You must supply a valid app label and module name.  Got "%s.%s"' % (label, model))

    if field_name:
        try:
            field = klass._meta.get_field(field_name)
            if not isinstance(field, GeometryField):
                raise FieldDoesNotExist
        except FieldDoesNotExist:
            raise Http404('Invalid geometry field.')

    connection = connections[using]

    if connection.features.has_AsKML_function:
        # Database will take care of transformation.
        placemarks = klass._default_manager.using(using).annotate(kml=AsKML(field_name))
    else:
        # If the database offers no KML method, we use the `kml`
        # attribute of the lazy geometry instead.
        placemarks = []
        if connection.features.has_Transform_function:
            qs = klass._default_manager.using(using).annotate(
                **{'%s_4326' % field_name: Transform(field_name, 4326)})
            field_name += '_4326'
        else:
            qs = klass._default_manager.using(using).all()
        for mod in qs:
            mod.kml = getattr(mod, field_name).kml
            placemarks.append(mod)

    # Getting the render function and rendering to the correct.
    if compress:
        render = render_to_kmz
    else:
        render = render_to_kml
    return render('gis/kml/placemarks.kml', {'places': placemarks}) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:47,代码来源:views.py

示例10: kml

# 需要导入模块: from django.contrib.gis.db.models import functions [as 别名]
# 或者: from django.contrib.gis.db.models.functions import Transform [as 别名]
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
    """
    This view generates KML for the given app label, model, and field name.

    The model's default manager must be GeoManager, and the field name
    must be that of a geographic field.
    """
    placemarks = []
    try:
        klass = apps.get_model(label, model)
    except LookupError:
        raise Http404('You must supply a valid app label and module name.  Got "%s.%s"' % (label, model))

    if field_name:
        try:
            field = klass._meta.get_field(field_name)
            if not isinstance(field, GeometryField):
                raise FieldDoesNotExist
        except FieldDoesNotExist:
            raise Http404('Invalid geometry field.')

    connection = connections[using]

    if connection.features.has_AsKML_function:
        # Database will take care of transformation.
        placemarks = klass._default_manager.using(using).annotate(kml=AsKML(field_name))
    else:
        # If the database offers no KML method, we use the `kml`
        # attribute of the lazy geometry instead.
        placemarks = []
        if connection.features.has_Transform_function:
            qs = klass._default_manager.using(using).annotate(
                **{'%s_4326' % field_name: Transform(field_name, 4326)})
            field_name += '_4326'
        else:
            qs = klass._default_manager.using(using).all()
        for mod in qs:
            mod.kml = getattr(mod, field_name).kml
            placemarks.append(mod)

    # Getting the render function and rendering to the correct.
    if compress:
        render = render_to_kmz
    else:
        render = render_to_kml
    return render('gis/kml/placemarks.kml', {'places': placemarks}) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:48,代码来源:views.py


注:本文中的django.contrib.gis.db.models.functions.Transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。