當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。