本文整理汇总了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
示例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
)
示例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
示例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)
示例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
示例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"))]
示例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()
示例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)
示例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)
示例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 ####
示例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
示例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
示例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)
示例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)
})
示例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()