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


Python geos.GEOSGeometry方法代码示例

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


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

示例1: test_change_component

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def test_change_component(self):
        state1 = Place.objects.get("state1") #west (our composite place will not be comprised with this one)
        state2 = Place.objects.get("state2") #south_east
        state3 = Place.objects.get("state3") #north_east
        comp_place1 = Place.objects.get(self.comp_place_id_1)
        comp_place1.add_relation(state2, "comprised_by", {"comment":"comp place comprised by state2"})
        comp_place1.add_relation(state3, "comprised_by", {"comment":"comp place comprised by state3"})
        comp_copy = comp_place1.copy()
        composite_area = GEOSGeometry(json.dumps(comp_copy.geometry)).area
        state3_area = GEOSGeometry(json.dumps(state3.geometry)).area
        
        state3.geometry = {"type":"Polygon", "coordinates":[[[-103.0892050625, 45.75121434375], [-94.3880331875, 46.01488621875], [-94.3880331875, 37.92894871875], [-103.0892050625, 37.92894871875], [-103.0892050625, 45.75121434375]]]}
        state3.save()
        state3_smaller_area = GEOSGeometry(json.dumps(state3.geometry)).area
        self.assertLess(state3_smaller_area, state3_area)
        comp_copy2 = comp_place1.copy()

        composite_smaller_area = GEOSGeometry(json.dumps(comp_copy2.geometry)).area
        self.assertLess(composite_smaller_area, composite_area)
        
                
    #if the component has its relation removed, it should change the composite place automatically 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:24,代码来源:tests.py

示例2: assign_admin

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def assign_admin(self):
        if self.is_composite or self.timeframe or not self.centroid:
            return False
        
        centroid_geom = str({"type":"Point", "coordinates": self.centroid})
        place_geom = GEOSGeometry(centroid_geom)

        temp_admin  = list(self.admin)
        for existing_admin in self.admin:
            if existing_admin.get("id"):
                temp_admin.remove(existing_admin)
                
        self.admin = list(temp_admin)

        results = AdminBoundary.objects.filter(queryable_geom__contains=place_geom)
        if results:
            for boundary in results:
                self.add_admin(boundary.to_place_json())
                
        return self.admin
        
    #unions a places geometry with another geometry 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:24,代码来源:place.py

示例3: union_geometry

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def union_geometry(self, target_geometry):
        #the target could have no geometry
        if not target_geometry:
            return True
        
        #composite place could have no geometry (especially at the beginning)    
        if not self.geometry:
            self.geometry = target_geometry
            return True
            
        place_geom = GEOSGeometry(json.dumps(self.geometry))
        target_geom = GEOSGeometry(json.dumps(target_geometry))
        union = place_geom.union(target_geom)
        self.geometry  = json.loads(union.json)
        return True
    
    #method for composite places.
    #Goes through the component places does a union on them and assigns the geometry to the result
    #Works with polygons and multipolygons or points and multipoints. 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:21,代码来源:place.py

示例4: _buffer

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def _buffer(geojson, width=0, unit="ft"):
    geojson = JSONSerializer().serialize(geojson)
    geom = GEOSGeometry(geojson, srid=4326)

    try:
        width = float(width)
    except Exception:
        width = 0

    if width > 0:
        if unit == "ft":
            width = width / 3.28084

        geom.transform(settings.ANALYSIS_COORDINATE_SYSTEM_SRID)
        geom = geom.buffer(width)
        geom.transform(4326)

    return geom 
开发者ID:archesproject,项目名称:arches,代码行数:20,代码来源:search.py

示例5: transform_value_for_tile

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def transform_value_for_tile(self, value, **kwargs):
        if "format" in kwargs and kwargs["format"] == "esrijson":
            arches_geojson = GeoUtils().arcgisjson_to_geojson(value)
        else:
            arches_geojson = {}
            arches_geojson["type"] = "FeatureCollection"
            arches_geojson["features"] = []
            geometry = GEOSGeometry(value, srid=4326)
            if geometry.geom_type == "GeometryCollection":
                for geom in geometry:
                    arches_json_geometry = {}
                    arches_json_geometry["geometry"] = JSONDeserializer().deserialize(GEOSGeometry(geom, srid=4326).json)
                    arches_json_geometry["type"] = "Feature"
                    arches_json_geometry["id"] = str(uuid.uuid4())
                    arches_json_geometry["properties"] = {}
                    arches_geojson["features"].append(arches_json_geometry)
            else:
                arches_json_geometry = {}
                arches_json_geometry["geometry"] = JSONDeserializer().deserialize(geometry.json)
                arches_json_geometry["type"] = "Feature"
                arches_json_geometry["id"] = str(uuid.uuid4())
                arches_json_geometry["properties"] = {}
                arches_geojson["features"].append(arches_json_geometry)

        return arches_geojson 
开发者ID:archesproject,项目名称:arches,代码行数:27,代码来源:datatypes.py

示例6: get_bounds_from_value

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def get_bounds_from_value(self, node_data):
        bounds = None
        for feature in node_data["features"]:
            geom_collection = GEOSGeometry(JSONSerializer().serialize(feature["geometry"]))

            if bounds is None:
                bounds = geom_collection.extent
            else:
                minx, miny, maxx, maxy = bounds
                if geom_collection.extent[0] < minx:
                    minx = geom_collection.extent[0]
                if geom_collection.extent[1] < miny:
                    miny = geom_collection.extent[1]
                if geom_collection.extent[2] > maxx:
                    maxx = geom_collection.extent[2]
                if geom_collection.extent[3] > maxy:
                    maxy = geom_collection.extent[3]

                bounds = (minx, miny, maxx, maxy)

        return bounds 
开发者ID:archesproject,项目名称:arches,代码行数:23,代码来源:datatypes.py

示例7: to_python

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def to_python(self, value):
        """
        Transforms the value to a Geometry object.
        """
        if value in self.empty_values:
            return None

        if not isinstance(value, GEOSGeometry):
            try:
                value = GEOSGeometry(value)
            except (GEOSException, ValueError, TypeError):
                raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')

        # Try to set the srid
        if not value.srid:
            try:
                value.srid = self.widget.map_srid
            except AttributeError:
                if self.srid:
                    value.srid = self.srid
        return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:fields.py

示例8: get_zoom

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def get_zoom(self, geom):
        "Returns the optimal Zoom level for the given geometry."
        # Checking the input type.
        if not isinstance(geom, GEOSGeometry) or geom.srid != 4326:
            raise TypeError('get_zoom() expects a GEOS Geometry with an SRID of 4326.')

        # Getting the envelope for the geometry, and its associated width, height
        # and centroid.
        env = geom.envelope
        env_w, env_h = self.get_width_height(env.extent)
        center = env.centroid

        for z in range(self._nzoom):
            # Getting the tile at the zoom level.
            tile_w, tile_h = self.get_width_height(self.tile(center, z).extent)

            # When we span more than one tile, this is an approximately good
            # zoom level.
            if (env_w > tile_w) or (env_h > tile_h):
                if z == 0:
                    raise GoogleMapException('Geometry width and height should not exceed that of the Earth.')
                return z - 1

        # Otherwise, we've zoomed in to the max.
        return self._nzoom - 1 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:zoom.py

示例9: to_python

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def to_python(self, value):
        """Transform the value to a Geometry object."""
        if value in self.empty_values:
            return None

        if not isinstance(value, GEOSGeometry):
            try:
                value = GEOSGeometry(value)
            except (GEOSException, ValueError, TypeError):
                raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')

        # Try to set the srid
        if not value.srid:
            try:
                value.srid = self.widget.map_srid
            except AttributeError:
                if self.srid:
                    value.srid = self.srid
        return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:fields.py

示例10: setUp

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def setUp(self):
        pnt_geom = GEOSGeometry('POINT(-123.5 48.5)')
        now_time = datetime.now()

        # Collision
        self._collision = Incident.objects.create(geom=pnt_geom, date=now_time,
                                                  i_type="Collision with moving object or vehicle",
                                                  incident_with="Vehicle, side",
                                                  injury="Injury, no treatment")
        # Nearmiss
        self._nearmiss = Incident.objects.create(geom=pnt_geom, date=now_time,
                                                 i_type="Near collision with stationary object or vehicle",
                                                 incident_with="Vehicle, side",
                                                 injury="Injury, no treatment")
        # Fall
        self._fall = Incident.objects.create(geom=pnt_geom, date=now_time,
                                             i_type="Fall",
                                             incident_with="Vehicle, side",
                                             injury="Injury, no treatment") 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:21,代码来源:tests.py

示例11: postAlertPolygon

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def postAlertPolygon(request):
	geofenceForm = GeofenceForm(request.POST)
	geofenceForm.data = geofenceForm.data.copy()

	# Create valid attributes for user and geom fields
	try:
		geofenceForm.data['user'] = request.user.id
		geofenceForm.data['geom'] = GEOSGeometry(geofenceForm.data['geom'])
	except(ValueError):
		messages.error(request, '<strong>' + _('Error') + '</strong><br>' + _('Invalid geometry data.'))

	if geofenceForm.is_valid():
		# Save new model object, send success message to the user
		polygon = geofenceForm.save()
		# messages.success(request, _('You will now receive alerts for the area traced.'))
		return JsonResponse({ 'success': True, 'polygon': GeoJSONSerializer().serialize([polygon,]) })
	else:
		return JsonResponse({'success': False}) 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:20,代码来源:alerts.py

示例12: instantiate_sub_class

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def instantiate_sub_class(self, feature_class, feature):
        """
            Instantiates an instance of the dynamic subclass of GeoJsonFeature based on the given feature.
        :param feature: A feature parsed django-geojson. The feature is actually reserialized to json in order to construct a GEOSGeometry instance.
        :return: An instance of the GeoJsonFeature subclass, which contains the geometry, properties of the feature, and perhaps the crs
        """
        # TODO, crs should be read from the geojson when present.
        # This crs isn't actually picked up by the GEOSGeometry constructor
        srid = settings.SRID_PREFIX.format(settings.DEFAULT_SRID)
        crs = {
            "type": "name",
            "properties": {
                "name": srid
            }
        }
        # Ironically, we have to rejsonify the data so that GEOSGeometry can parse the feature as json
        json = jsonify({'type':feature.geometry.type, 'coordinates':feature.geometry.coordinates, 'crs':crs})
        geometry = GEOSGeometry(json)
        field_dict = map_to_dict(lambda field: [field.name, feature.properties[field.name]],
                                 filter(lambda field: feature.properties.get(field.name, None), feature_class._meta.fields))
        return feature_class(wkb_geometry=geometry, **field_dict) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:23,代码来源:geo_json_processor.py

示例13: globalSetup

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def globalSetup():

    # Bootstrap
    GlobalConfig._no_post_save_publishing = True
    GlobalConfig.objects.update_or_create(
        key=Keys.GLOBAL_CONFIG_KEY,
        defaults=dict(bounds=GEOSGeometry('MULTIPOLYGON EMPTY'))
    )
    GlobalConfig._no_post_save_publishing = False

    update_or_create_group('superadmin')
    update_or_create_user(username='superadmin', password='test_superadmin_user@uf', email='test_superadmin_user@calthorpeanalytics.com',
                          api_key=None, groups=['superadmin'], is_super_user=True)

    return GlobalConfig.objects.update_or_create(
        key='global',
        defaults=dict(
            name='Global Config',
            scope='global',
            bounds='MULTIPOLYGON (((-20037508.3399999998509884 -20037508.3399999998509884, -20037508.3399999998509884 20037508.3399999998509884, \
                20037508.3399999998509884 20037508.3399999998509884, 20037508.3399999998509884 -20037508.3399999998509884, \
                -20037508.3399999998509884 -20037508.3399999998509884)))'
        )
    )[0] 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:26,代码来源:test_user_management.py

示例14: to_internal_value

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def to_internal_value(self, value):
        """
        Parse json data and return a point object
        """
        if value in EMPTY_VALUES and not self.required:
            return None

        if isinstance(value, string_types):
            try:
                value = value.replace("'", '"')
                value = json.loads(value)
            except ValueError:
                self.fail('invalid')

        if value and isinstance(value, dict):
            try:
                latitude = value.get("latitude")
                longitude = value.get("longitude")
                return GEOSGeometry('POINT(%(longitude)s %(latitude)s)' % {
                    "longitude": longitude,
                    "latitude": latitude}
                )
            except (GEOSException, ValueError):
                self.fail('invalid')
        self.fail('invalid') 
开发者ID:Hipo,项目名称:drf-extra-fields,代码行数:27,代码来源:geo_fields.py

示例15: to_representation

# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSGeometry [as 别名]
def to_representation(self, value):
        """
        Transform POINT object to json.
        """
        if value is None:
            return value

        if isinstance(value, GEOSGeometry):
            value = {
                "latitude": value.y,
                "longitude": value.x
            }

        if self.str_points:
            value['longitude'] = smart_str(value.pop('longitude'))
            value['latitude'] = smart_str(value.pop('latitude'))

        return value 
开发者ID:Hipo,项目名称:drf-extra-fields,代码行数:20,代码来源:geo_fields.py


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