當前位置: 首頁>>代碼示例>>Python>>正文


Python geos.Point方法代碼示例

本文整理匯總了Python中django.contrib.gis.geos.Point方法的典型用法代碼示例。如果您正苦於以下問題:Python geos.Point方法的具體用法?Python geos.Point怎麽用?Python geos.Point使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.gis.geos的用法示例。


在下文中一共展示了geos.Point方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: import_gazetteer

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def import_gazetteer(f, limit):
    t = csv.reader(f, delimiter="\t")
    i = 0
    for row in t:
        ft = Feature()
        if Feature.objects.filter(url=row[0]).count() > 0:
            print "duplicate row " + row[0]
        else:
            ft.url = row[0]
            ft.preferred_name = row[1]

            try:
                fcode = FeatureType.objects.get(code=row[2])
            except:
                fcode = None

            ft.feature_type = fcode
            ft.admin1 = row[4]
            ft.admin2 = row[5]
            ft.geometry = Point(float(row[7]), float(row[6]))
            ft.save()
            print "saved " + ft.preferred_name
            i += 1
            if i > limit:
                break 
開發者ID:LibraryOfCongress,項目名稱:gazetteer,代碼行數:27,代碼來源:imports.py

示例2: __init__

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def __init__(self, *args, **kwargs):
        is_new = kwargs.pop('new', None)
        org_id = kwargs.pop('organization_id', None)
        super(ProjectForm, self).__init__(*args, **kwargs)

        if not self.fields['location'].initial:
            self.fields['location'].initial = Point(85.3240, 27.7172,srid=4326)
        self.fields['type'].empty_label = None
        self.fields['cluster_sites'].label = "Do you want to cluster sites in this Project?"
        #self.fields['organization'].empty_label = None

        if not is_new:
            org_id = kwargs['instance'].organization.id
        self.fields['geo_layers'].queryset = GeoLayer.objects.filter(
            organization__id=org_id
        ) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:18,代碼來源:forms.py

示例3: update

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def update(self, instance, validated_data):
        data = self.context['request'].data
        type_id = data.pop('type')
        site_type = ProjectType.objects.get(pk=type_id)
        verify_survey = data.pop('is_survey')
        if verify_survey:
            validated_data.update({'is_survey': False})
            validated_data.update({'is_active': True})
        else:
            validated_data.update({'is_survey': True})
            validated_data.update({'is_active': False})

        p = Point(float(validated_data.pop('longitude')), float(validated_data.pop('latitude')), srid=4326)
        validated_data.update({'location':p})
        Site.objects.filter(pk=instance.pk).update(**validated_data)
        site = Site.objects.get(pk=instance.id)
        site.type = site_type
        site.save()
        return site 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:21,代碼來源:SiteSerializer.py

示例4: _set_geom

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def _set_geom(self):
        xform = self.xform
        data_dictionary = xform.data_dictionary()
        geo_xpaths = data_dictionary.geopoint_xpaths()
        doc = self.get_dict()
        points = []

        if len(geo_xpaths):
            for xpath in geo_xpaths:
                geometry = [float(s) for s in doc.get(xpath, u'').split()]

                if len(geometry):
                    lat, lng = geometry[0:2]
                    points.append(Point(lng, lat))

            if not xform.instances_with_geopoints and len(points):
                xform.instances_with_geopoints = True
                xform.save()

            self.geom = GeometryCollection(points) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:22,代碼來源:instance.py

示例5: geocode

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def geocode(query, country='', private=False, annotations=False, multiple=False):
    key = SiteConfiguration.get_solo().opencage_api_key
    lang = settings.LANGUAGE_CODE
    if not query:
        return
    params = {'language': lang}
    if not annotations:
        params.update({'no_annotations': int(not annotations)})
    if private:
        params.update({'no_record': int(private)})
    if country:
        params.update({'countrycode': country})
    result = geocoder.opencage(query, key=key, params=params, maxRows=15 if multiple else 1)
    logging.getLogger('PasportaServo.geo').debug(
        "Query: %s\n\tResult: %s\n\tConfidence: %d", query, result, result.confidence)
    result.point = Point(result.xy, srid=SRID) if result.xy else None
    return result 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:19,代碼來源:utils.py

示例6: make_property_map

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def make_property_map():
    def _g(p, default=UNSET):
        return lambda d: d.get(p, default)

    def _G(p):
        return lambda d: d[p]

    def get_other_addresses(d):
        return ";".join(d["all_addresses"][1:]) if "all_addresses" in d else ""

    return [("address", lambda d: d["all_addresses"][0]),
            ("other_addresses", get_other_addresses),
            ("location", lambda d: Point(d["location"]["long"], d["location"]["lat"])),
            ("summary", lambda d: d["summary"][0:1024] if "summary" in d else UNSET),
            ("description", _g("description")),
            ("source", _g("source")),
            ("region_name", _g("region_name")),
            ("complete", _g("complete")),
            ("status", _g("status"))] 
開發者ID:codeforboston,項目名稱:cornerwise,代碼行數:21,代碼來源:models.py

示例7: process_stops

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def process_stops(feed, csvreader):
    print('Processing stops')
    existing = {}
    for stop in Stop.objects.filter(feed=feed):
        existing[stop.gtfs_stop_id] = stop

    for row in csvreader:
        gtfs_stop_id = row['stop_id']
        stop = existing.get(gtfs_stop_id, None)
        changed = False
        values = {}
        values['name'] = row['stop_name']
        x = float(row['stop_lon'])
        y = float(row['stop_lat'])
        values['position'] = Point(x, y, srid=4326)
        if stop is None:
            stop = Stop(feed=feed, gtfs_stop_id=gtfs_stop_id)
            changed = True
        for value in values:
            prev = getattr(stop, value)
            if prev != values[value]:
                setattr(stop, value, values[value])
                changed = True
        if changed:
            stop.save() 
開發者ID:katharosada,項目名稱:bus-shaming,代碼行數:27,代碼來源:upsert_timetable_data.py

示例8: test_put_update_coordinates

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def test_put_update_coordinates(self):
        self.assertEqual(self.location_model.objects.count(), 0)
        dl = self._create_object_location()
        url = reverse(self.url_name, args=[dl.device.pk])
        url = '{0}?key={1}'.format(url, dl.device.key)
        self.assertEqual(self.location_model.objects.count(), 1)
        coords = json.loads(Point(2, 23).geojson)
        feature = json.dumps({'type': 'Feature', 'geometry': coords})
        r = self.client.put(url, feature, content_type='application/json')
        self.assertEqual(r.status_code, 200)
        self.assertDictEqual(
            r.json(),
            {
                'type': 'Feature',
                'geometry': coords,
                'properties': {'name': dl.location.name},
            },
        )
        self.assertEqual(self.location_model.objects.count(), 1) 
開發者ID:openwisp,項目名稱:openwisp-controller,代碼行數:21,代碼來源:test_api.py

示例9: form_valid

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def form_valid(self, form):
        form.instance.location = Point(
            (float(form.cleaned_data['location_lon']), float(form.cleaned_data['location_lat']))
        )

        return super(ReportIncidentView, self).form_valid(form) 
開發者ID:abarto,項目名稱:tracker_project,代碼行數:8,代碼來源:views.py

示例10: geos

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def geos(self, query):
        "Returns a GEOS Point object for the given query."
        ll = self.lon_lat(query)
        if ll:
            from django.contrib.gis.geos import Point
            return Point(ll, srid=4326)
        else:
            return None

    # #### GeoIP Database Information Routines #### 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:12,代碼來源:base.py

示例11: get_lon_lat

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def get_lon_lat(self, lonlat):
        "Unpacks longitude, latitude from GEOS Points and 2-tuples."
        if isinstance(lonlat, Point):
            lon, lat = lonlat.coords
        else:
            lon, lat = lonlat
        return lon, lat 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:zoom.py

示例12: get_width_height

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def get_width_height(self, extent):
        """
        Returns the width and height for the given extent.
        """
        # Getting the lower-left, upper-left, and upper-right
        # coordinates from the extent.
        ll = Point(extent[:2])
        ul = Point(extent[0], extent[3])
        ur = Point(extent[2:])
        # Calculating the width and height.
        height = ll.distance(ul)
        width = ul.distance(ur)
        return width, height 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:zoom.py

示例13: ajax_upload_sites

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def ajax_upload_sites(request, pk):
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        count = 0
        project = Project(pk=pk)
        try:
            sites = request.FILES['file'].get_records()
            count = len(sites)
            with transaction.atomic():
                for site in sites:
                    site = dict((k,v) for k,v in site.iteritems() if v is not '')
                    lat = site.get("longitude", 85.3240)
                    long = site.get("latitude", 27.7172)
                    location = Point(lat, long, srid=4326)
                    type_id = int(site.get("type", "0"))
                    _site, created = Site.objects.get_or_create(identifier=str(site.get("id")), name=site.get("name"),
                                                                project=project, type_id=type_id)
                    _site.phone = site.get("phone")
                    _site.address = site.get("address")
                    _site.public_desc = site.get("public_desc"),
                    _site.additional_desc = site.get("additional_desc")
                    _site.location=location
                    if type_id:
                        _site.type = SiteType.objects.get(pk=type_id)
                    _site.save()
            if count:
                noti = project.logs.create(source=request.user, type=12, title="Bulk Sites",
                                       organization=project.organization,
                                       project=project, content_object=project,
                                       extra_message=count + "Sites",
                                       description='{0} created a {1} sites in {2}'.
                                           format(request.user.get_full_name(), count, project.name))
                result = {}
                result['description'] = noti.description
                result['url'] = noti.get_absolute_url()
                ChannelGroup("project-{}".format(project.id)).send({"text": json.dumps(result)})
            return Response({'msg': 'ok'}, status=status.HTTP_200_OK)
        except Exception as e:
            return Response({'file':e.message}, status=status.HTTP_400_BAD_REQUEST)
    return Response(form.errors, status=status.HTTP_400_BAD_REQUEST) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:42,代碼來源:views.py

示例14: get

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def get(self, request, pk, **kwargs):
        coord_datas = get_site_responses_coords(pk)
        obj = Site.objects.get(pk=self.kwargs.get('pk'))
        response_coords = list(coord_datas["result"])
        response_coords.append({'geometry': {'coordinates': [obj.latitude, obj.longitude], 'type': 'Point'},
                                              'properties': {'fs_uuid': 'None',
                                              'id':'#' ,
                                              'submitted_by': 'site_origin'},
                                              'type': 'Feature'})
        return render(request, 'fieldsight/site_response_map_view.html', {
            'co_ords': json.dumps(response_coords, cls=DjangoJSONEncoder, ensure_ascii=False).encode('utf8'),
            'geo_layers': obj.project.geo_layers.all(),
            'is_donor_only' : kwargs.get('is_donor_only', False)
        }) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:16,代碼來源:views.py

示例15: clean

# 需要導入模塊: from django.contrib.gis import geos [as 別名]
# 或者: from django.contrib.gis.geos import Point [as 別名]
def clean(self):
        lat = self.data.get("Longitude","85.3240")
        long = self.data.get("Latitude","27.7172")
        p = Point(round(float(lat), 6), round(float(long), 6),srid=4326)
        self.cleaned_data["location"] = p
        super(OrganizationForm, self).clean() 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:8,代碼來源:forms.py


注:本文中的django.contrib.gis.geos.Point方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。