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


Python measure.D属性代码示例

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


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

示例1: __init__

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def __init__(self, *args, min_value=D(m=10), max_value=D(m=100),
                 initial_unit="ft", **kwargs):
        error_messages = {
            "incomplete": "Enter a distance"
        }
        self.min_value = min_value
        self.max_value = max_value
        fields = (
            FloatField(),
            ChoiceField(choices=self.DISTANCE_UNITS,
                        initial=initial_unit)
        )
        super().__init__(
            fields=fields,
            error_messages=error_messages,
            require_all_fields=True,
            *args, **kwargs
        )
        self.widget = DistanceWidget(choices=self.DISTANCE_UNITS) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:21,代码来源:widgets.py

示例2: test_site_restrictions

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def test_site_restrictions(self):
        """
        Check that site-specific constraints are checked.
        """
        subscription = models.Subscription(
            site_name="somerville.cornerwise.gov")
        query = add_radius({})
        query["r"] = D(ft=10000).m

        with self.assertRaises(ValidationError):
            subscription.set_validated_query(query)

        with self.assertRaises(ValidationError):
            subscription.set_validated_query(add_box({}))

        query["r"] = "300m"
        query["region_name"] = "Tunguska, Krasnoyarsk Krai"

        with self.assertRaises(ValidationError):
            subscription.set_validated_query(query) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:22,代码来源:tests.py

示例3: readable_query

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def readable_query(query, unit="ft"):
        # NOTE Not currently used, but may be useful again in the future
        if "projects" in query:
            if query["project"] == "all":
                desc = "Public proposals "
            else:
                desc = "Private proposals "
        else:
            desc = "All proposals "

        if "text" in query:
            desc += "matching \"" + query["text"] + "\" "

        if "box" in query:
            box = bounds_from_box(query["box"])
            sw, ne = poly_bounds(box)
            desc += "".join(["inside the region: ",
                             prettify_point(sw), " and ", prettify_point(ne)])
        elif "center" in query:
            dist = D(m=query["r"])

        return desc 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:24,代码来源:models.py

示例4: nel_raggio

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def nel_raggio(self, ricerca):
        """
        Filtra una ricerca, per gli elementi nel raggio di questo elemento.
        :return: La ricerca filtrata
        """
        from formazione.models import CorsoBase

        if not self.locazione:
            # Check per restituire <QuerySet> dello stesso tipo di oggetto <ricerca>
            if ricerca.model is CorsoBase:
                return CorsoBase.objects.none()

            return self.__class__.objects.none()

        q = ricerca.filter(locazione__geo__distance_lte=(self.locazione.geo, D(km=self.raggio)))
        return q 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:18,代码来源:geo.py

示例5: decompress

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def decompress(self, distance):
        if not isinstance(distance, D):
            distance = D(ft=distance)
        return [distance.ft, distance._default_unit] 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:6,代码来源:widgets.py

示例6: compress

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def compress(self, values):
        return D(**{values[1]: values[0]}) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:4,代码来源:widgets.py

示例7: get_subscribers

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def get_subscribers(geocoded=[], proposals=[],
                    region=settings.GEO_REGION,
                    notify_radius=D(ft=300)):
    """Get the Subscriptions that should be informed about the given geocoded
    addresses and/or proposals. Returns a dictionary of Subscriptions to
    (address/proposal, Point).

    :param geocoded: a list of tuples (address, Point, formatted_address)
    :param proposals: a list of Proposals

    """
    if not isinstance(notify_radius, D):
        notify_radius = D(ft=notify_radius)

    def unpack(x):
        return (x, x.location) if isinstance(x, Proposal) else (x[0], x[1])

    sub_near = defaultdict(list)
    for thing, point in map(unpack, chain(proposals, geocoded)):
        if notify_radius:
            subs = Subscription.objects.filter(
                center__distance_lte=(point, notify_radius))
        else:
            subs = Subscription.objects.containing(point)

        for sub in subs:
            sub_near[sub].append((thing, point))

    return sub_near 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:31,代码来源:staff_notifications.py

示例8: distance_from_str

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def distance_from_str(distance):
    if isinstance(distance, str):
        m = re.match(distance_patt, distance)
        if m:
            unit = m.group(2) or "m"
            return D(**{unit: float(m.group(1))})
    else:
        return D(m=float(distance)) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:10,代码来源:utils.py

示例9: area_description

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def area_description(self, dist_units="ft"):
        if self.box:
            sw, ne = poly_bounds(self.box)
            return ("inside the region bounded by "
                    f"{prettify_point(sw)} and {prettify_point(ne)}")

        if self.center:
            dist = round(getattr(D(m=self.radius), dist_units))
            return "within {dist} {dist_units} of {where}".format(
                dist=dist,
                dist_units=dist_units,
                where=(self.address or prettify_point(self.center))
            ) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:15,代码来源:models.py

示例10: _get_nearby_factories

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def _get_nearby_factories(latitude, longitude, radius):
    """Return nearby factories based on position and search range."""
    # NOTE: if we use h3 for geoencoding in the future, we can use h3.k_ring():
    # ref: https://observablehq.com/@nrabinowitz/h3-radius-lookup
    pnt = Point(x=longitude, y=latitude, srid=4326)
    pnt.transform(settings.POSTGIS_SRID)
    ids = Factory.objects.only("id").filter(point__distance_lte=(pnt, D(km=radius)))
    if len(ids) > settings.MAX_FACTORY_PER_GET:
        ids = _sample(ids, settings.MAX_FACTORY_PER_GET)
    return Factory.objects.filter(id__in=[obj.id for obj in ids]) 
开发者ID:Disfactory,项目名称:Disfactory,代码行数:12,代码来源:utils.py

示例11: test_get_nearby_factories_called_db_correctlly

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def test_get_nearby_factories_called_db_correctlly(self):
        lat = 25
        lng = 120
        radius = 2.  # km
        pnt = Point(x=lng, y=lat, srid=4326)
        pnt.transform(3857)
        d = D(km=radius)
        # with patch("api.views.utils.Factory.objects.filter") as mock_filter:
        #     _get_nearby_factories(lat, lng, radius=radius)
        #     mock_filter.assert_called_once_with(point__distance_lte=(pnt, d)) 
开发者ID:Disfactory,项目名称:Disfactory,代码行数:12,代码来源:test_utils.py

示例12: test_migration_seed_data_correctly

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def test_migration_seed_data_correctly(self):
        pnt = Point(x=120.1, y=23.234, srid=4326)
        pnt.transform(3857)
        factories = Factory.objects.filter(point__distance_lte=(pnt, D(km=1)))
        self.assertEqual(set([factory.name for factory in factories]), set([
            "既有違章工廠 No.2",
            "既有違章工廠 No.3",
            "既有違章工廠 No.8",
            "既有違章工廠 No.9",
            "既有違章工廠 No.10",
            "既有違章工廠 No.11",
            "既有違章工廠 No.12",
            "既有違章工廠 No.13",
            "既有違章工廠 No.22",
        ])) 
开发者ID:Disfactory,项目名称:Disfactory,代码行数:17,代码来源:test_models.py

示例13: end

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def end(self, end_position=None):
        self.rent_end = now()
        if end_position is not None:
            self.end_position = end_position
        elif self.bike.public_geolocation():
            self.end_position = self.bike.public_geolocation().geo
        self.save()

        if self.end_position:
            # attach bike to station if location is closer than X meters
            # distance is configured in preferences
            max_distance = preferences.BikeSharePreferences.station_match_max_distance
            station_closer_than_Xm = Station.objects.filter(
                location__distance_lte=(self.end_position, D(m=max_distance)),
                status="AC",
            ).first()
            if station_closer_than_Xm:
                self.bike.current_station = station_closer_than_Xm
                self.end_station = station_closer_than_Xm
                self.save()
            else:
                self.bike.current_station = None

        # set Bike status back to available
        self.bike.availability_status = "AV"
        self.bike.save()
        try:
            # set new non static bike ID, so for GBFS observers can not track this bike
            self.bike.non_static_bike_uuid = uuid.uuid4()
            self.bike.save()
        except IntegrityError:
            # Congratulations! The 2^64 chance of uuid4 collision has happend.
            # here coul'd be the place for the famous comment: "should never happen"
            # So we catch this error here, but don't handle it.
            # because don't rotating a uuid every 18,446,744,073,709,551,615 rents is ok
            pass 
开发者ID:stadtulm,项目名称:cykel,代码行数:38,代码来源:models.py

示例14: test02_distance_lookup

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def test02_distance_lookup(self):
        "Testing distance lookup support on non-point geography fields."
        z = Zipcode.objects.get(code='77002')
        cities1 = list(City.objects
                       .filter(point__distance_lte=(z.poly, D(mi=500)))
                       .order_by('name')
                       .values_list('name', flat=True))
        cities2 = list(City.objects
                       .filter(point__dwithin=(z.poly, D(mi=500)))
                       .order_by('name')
                       .values_list('name', flat=True))
        for cities in [cities1, cities2]:
            self.assertEqual(['Dallas', 'Houston', 'Oklahoma City'], cities) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例15: updatebikelocation

# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import D [as 别名]
def updatebikelocation(request):
    device_id = request.data.get("device_id")
    if not (device_id):
        return Response({"error": "device_id missing"}, status=400)
    try:
        tracker = LocationTracker.objects.get(device_id=device_id)
    except LocationTracker.DoesNotExist:
        return Response({"error": "tracker does not exist"}, status=404)

    serializer = LocationTrackerUpdateSerializer(tracker, data=request.data)
    if not serializer.is_valid():
        return Response(serializer.errors, status=400)

    serializer.save()

    lat = request.data.get("lat")
    lng = request.data.get("lng")
    accuracy = request.data.get("accuracy")
    loc = None

    if lat and lng:
        loc = Location.objects.create(source="TR", reported_at=now())
        if tracker.bike:
            loc.bike = tracker.bike
        loc.geo = Point(float(lng), float(lat), srid=4326)
        loc.tracker = tracker
        if accuracy:
            loc.accuracy = accuracy
        loc.save()

    if tracker.bike:
        bike = tracker.bike
        bike.last_reported = now()

        if loc:
            # check if bike is near station and assign it to that station
            # distance ist configured in prefernces
            max_distance = preferences.BikeSharePreferences.station_match_max_distance
            station_closer_than_Xm = Station.objects.filter(
                location__distance_lte=(loc.geo, D(m=max_distance)), status="AC"
            ).first()
            if station_closer_than_Xm:
                bike.current_station = station_closer_than_Xm
            else:
                bike.current_station = None

        bike.save()

    if not loc:
        return Response({"success": True, "warning": "lat/lng missing"})

    return Response({"success": True}) 
开发者ID:stadtulm,项目名称:cykel,代码行数:54,代码来源:views.py


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