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


Python models.GeometryField方法代码示例

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


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

示例1: resolve_field

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def resolve_field(meta):
        type = meta['type']
        rest = merge(filter_dict(
            # Don't allow default='SEQUENCE'
            lambda key, value: not (key=='default' and value=='SEQUENCE'),
            # Ignore these keys
            remove_keys(meta, ['type', 'auto_populate', 'visible', 'geometry_type', 'nullable'])
        ), dict(null=True))
        if type=='string':
            return models.CharField(**rest)
        elif type=='integer':
            return models.IntegerField(**rest)
        elif type=='float':
            return models.FloatField(**rest)
        elif type=='biginteger':
            return models.BigIntegerField(**rest)
        elif type=='geometry':
            return models.GeometryField(geography=False, **rest)
        elif type=='date':
            return models.DateField(**rest)
        elif type=='datetime':
            return models.DateTimeField(**rest) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:24,代码来源:feature_class_creator.py

示例2: formfield_for_dbfield

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def formfield_for_dbfield(self, db_field, **kwargs):
        """
        Overloaded from ModelAdmin so that an OpenLayersWidget is used
        for viewing/editing 2D GeometryFields (OpenLayers 2 does not support
        3D editing).
        """
        if isinstance(db_field, models.GeometryField) and db_field.dim < 3:
            kwargs.pop('request', None)
            # Setting the widget with the newly defined widget.
            kwargs['widget'] = self.get_map_widget(db_field)
            return db_field.formfield(**kwargs)
        else:
            return super(GeoModelAdmin, self).formfield_for_dbfield(db_field, **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:15,代码来源:options.py

示例3: feature_kwargs

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def feature_kwargs(self, feat):
        """
        Given an OGR Feature, this will return a dictionary of keyword arguments
        for constructing the mapped model.
        """
        # The keyword arguments for model construction.
        kwargs = {}

        # Incrementing through each model field and OGR field in the
        # dictionary mapping.
        for field_name, ogr_name in self.mapping.items():
            model_field = self.fields[field_name]

            if isinstance(model_field, GeometryField):
                # Verify OGR geometry.
                try:
                    val = self.verify_geom(feat.geom, model_field)
                except GDALException:
                    raise LayerMapError('Could not retrieve geometry from feature.')
            elif isinstance(model_field, models.base.ModelBase):
                # The related _model_, not a field was passed in -- indicating
                # another mapping for the related Model.
                val = self.verify_fk(feat, model_field, ogr_name)
            else:
                # Otherwise, verify OGR Field type.
                val = self.verify_ogr_field(feat[ogr_name], model_field)

            # Setting the keyword arguments for the field name with the
            # value obtained above.
            kwargs[field_name] = val

        return kwargs 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:34,代码来源:layermapping.py

示例4: geometry_field

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def geometry_field(self):
        "Returns the GeometryField instance associated with the geographic column."
        # Use `get_field()` on the model's options so that we
        # get the correct field instance if there's model inheritance.
        opts = self.model._meta
        return opts.get_field(self.geom_field) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:layermapping.py

示例5: make_multi

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def make_multi(self, geom_type, model_field):
        """
        Given the OGRGeomType for a geometry and its associated GeometryField,
        determine whether the geometry should be turned into a GeometryCollection.
        """
        return (geom_type.num in self.MULTI_TYPES and
                model_field.__class__.__name__ == 'Multi%s' % geom_type.django) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:layermapping.py

示例6: formfield_for_dbfield

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def formfield_for_dbfield(self, db_field, request, **kwargs):
        """
        Overloaded from ModelAdmin so that an OpenLayersWidget is used
        for viewing/editing 2D GeometryFields (OpenLayers 2 does not support
        3D editing).
        """
        if isinstance(db_field, models.GeometryField) and db_field.dim < 3:
            # Setting the widget with the newly defined widget.
            kwargs['widget'] = self.get_map_widget(db_field)
            return db_field.formfield(**kwargs)
        else:
            return super().formfield_for_dbfield(db_field, request, **kwargs) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:14,代码来源:options.py

示例7: feature_kwargs

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def feature_kwargs(self, feat):
        """
        Given an OGR Feature, return a dictionary of keyword arguments for
        constructing the mapped model.
        """
        # The keyword arguments for model construction.
        kwargs = {}

        # Incrementing through each model field and OGR field in the
        # dictionary mapping.
        for field_name, ogr_name in self.mapping.items():
            model_field = self.fields[field_name]

            if isinstance(model_field, GeometryField):
                # Verify OGR geometry.
                try:
                    val = self.verify_geom(feat.geom, model_field)
                except GDALException:
                    raise LayerMapError('Could not retrieve geometry from feature.')
            elif isinstance(model_field, models.base.ModelBase):
                # The related _model_, not a field was passed in -- indicating
                # another mapping for the related Model.
                val = self.verify_fk(feat, model_field, ogr_name)
            else:
                # Otherwise, verify OGR Field type.
                val = self.verify_ogr_field(feat[ogr_name], model_field)

            # Setting the keyword arguments for the field name with the
            # value obtained above.
            kwargs[field_name] = val

        return kwargs 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:34,代码来源:layermapping.py

示例8: geometry_field

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def geometry_field(self):
        "Return the GeometryField instance associated with the geographic column."
        # Use `get_field()` on the model's options so that we
        # get the correct field instance if there's model inheritance.
        opts = self.model._meta
        return opts.get_field(self.geom_field) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:8,代码来源:layermapping.py

示例9: get_fields

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def get_fields(self):
        """Returns a fields dict for this serializer with a 'geometry' field
        added.
        """
        fields = super(GeoModelSerializer, self).get_fields()
        # Set the geometry field name when it's undeclared.
        if not self.Meta.geom_field:
            for name, field in fields.items():
                if isinstance(field, GeometryField):
                    self.Meta.geom_field = name
                    break
        return fields 
开发者ID:bkg,项目名称:django-spillway,代码行数:14,代码来源:serializers.py

示例10: geo_field

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def geo_field(queryset):
    """Returns the GeometryField for a django or spillway GeoQuerySet."""
    for field in queryset.model._meta.fields:
        if isinstance(field, models.GeometryField):
            return field
    raise exceptions.FieldDoesNotExist('No GeometryField found') 
开发者ID:bkg,项目名称:django-spillway,代码行数:8,代码来源:query.py

示例11: geography_type

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def geography_type(cls):
        return None

    # todo: we don't need to use the layermapping importer for peer tables, so let's only put this on the base tables
    # Because of the layer importer we need this even though the geometry is in the Geography instance
    #wkb_geometry = models.GeometryField() 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:8,代码来源:geographic.py

示例12: test_geometry_value_annotation

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def test_geometry_value_annotation(self):
        p = Point(1, 1, srid=4326)
        point = City.objects.annotate(p=Value(p, GeometryField(srid=4326))).first().p
        self.assertEqual(point, p) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_expressions.py

示例13: test_geometry_value_annotation_different_srid

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def test_geometry_value_annotation_different_srid(self):
        p = Point(1, 1, srid=32140)
        point = City.objects.annotate(p=Value(p, GeometryField(srid=4326))).first().p
        self.assertTrue(point.equals_exact(p.transform(4326, clone=True), 10 ** -5))
        self.assertEqual(point.srid, 4326) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_expressions.py

示例14: test_geography_value

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def test_geography_value(self):
        p = Polygon(((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
        area = City.objects.annotate(a=functions.Area(Value(p, GeometryField(srid=4326, geography=True)))).first().a
        self.assertAlmostEqual(area.sq_km, 12305.1, 0) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_expressions.py

示例15: dynamic_join_model_class

# 需要导入模块: from django.contrib.gis.db import models [as 别名]
# 或者: from django.contrib.gis.db.models import GeometryField [as 别名]
def dynamic_join_model_class(self, join_models, related_field_names):
        """
            Creates an unmanaged subclass of the feature class with extra fields to represent the
            the fields of the join_models. This also adds fields for any fields specified in the
            related_model_lookup. This is not for join models but ForeignKeys such as BuiltForm
            These latter fields must be specified explicitly because the main model and join models
            can't populate their foreign keys from the query because the query has to be
            a ValuesQuerySet in order to do the join. So we create id versions of the fields here
            (e.g. built_form_id) which the query can fill and then use that to manually
            set the foreign key reference in the Tastypie resource.
            :param join_models: Other feature models whose attributes should be added to the subclass
            :param related_field_names: List of field names of foreign key id fields (AutoFields)

        """
        main_model_class = self.dynamic_model_class()
        manager = main_model_class.objects
        # Exclude the following field types. Since the base Feature defines an id we'll still get that, which we want
        exclude_field_types = (ForeignKey, ToManyField, OneToOneField, GeometryField)
        all_field_paths_to_fields = merge(
            # Create fields to represented foreign key id fields
            # Our query fetches these ids since it can't fetch related objects (since its a values() query)
            map_to_dict(
                lambda field_name: [field_name.replace('__', '_x_'),
                                    IntegerField(field_name.replace('__', '_x_'), null=True)],
                related_field_names
            ),
            # The join fields for each joined related model
            *map(
                lambda related_model: related_field_paths_to_fields(
                    manager,
                    related_model,
                    exclude_field_types=exclude_field_types,
                    fields=limited_api_fields(related_model),
                    separator='_x_'),
                join_models)
        )

        abstract_feature_class = resolve_module_attr(self.configuration.abstract_class_name)
        # Make sure the class name is unique to the related models and the given ConfigEntity
        related_models_unique_id = '_'.join(sorted(map(lambda related_model: related_model.__name__, join_models), ))
        dynamic_model_clazz = dynamic_model_class(
            main_model_class,
            self.db_entity.schema,
            self.db_entity.table,
            class_name="{0}{1}{2}{3}Join".format(
                abstract_feature_class.__name__,
                self.db_entity.id,
                self.config_entity.id,
                related_models_unique_id),
            fields=all_field_paths_to_fields,
            class_attrs=self.configuration.class_attrs or {},
            related_class_lookup=self.configuration.related_class_lookup or {},
            is_managed=False,
            cacheable=False)
        logger.info("Created dynamic join model class %s" % dynamic_model_clazz)
        logger.debug("Created with model fields %s" % map(lambda field: field.name, dynamic_model_clazz._meta.fields))
        logger.debug("Created with related and join fields %s" % all_field_paths_to_fields)
        return dynamic_model_clazz 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:60,代码来源:feature_class_creator.py


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