geodjango

GeoDjango: How to create a circle based on point and radius

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 02:41:48
I have the following (simplified) Model: class Zone(gismodels.Model): name = gismodels.CharField() poly = gismodels.PolygonField() I want to create and save a polygon that represents a circle, based upon a given point and radius. The only way I can figure out how to achieve this, is to call the postgis ST_Buffer function using raw SQL. I'm really hoping that there is another way. Is it possible to access the GEOS buffer methods? Yes, it is possible to use the geos buffer method : >>> from django.contrib.gis import geos >>> center = geos.Point(5, 5) >>> radius = 2 >>> circle = center.buffer

Howto merge 2 Django QuerySets in one and make a SELECT DISTINCT

喜你入骨 提交于 2019-11-29 16:39:35
问题 models.py class SinglePoint(models.Model): attributes = models.TextField(blank=True) name = models.CharField(max_length=100) geom = models.PointField() #Kartenposition objects = models.GeoManager() class Connection(models.Model): name = models.CharField(max_length=100) #points = models.ManyToManyField(SinglePoint) #OLD p1 = models.ForeignKey(SinglePoint, related_name='p1_set') #NEW p2 = models.ForeignKey(SinglePoint, related_name='p2_set') #NEW obs = models.ManyToManyField(Observation, blank

Latitude/longitude widget for pointfield?

被刻印的时光 ゝ 提交于 2019-11-29 13:44:04
问题 Is there a widget for PointField as separate latitude/longitude inputs? Like SplitDateTimeWidget for DateTimeField. 回答1: Here's my working custom field and widget: class LatLongWidget(forms.MultiWidget): """ A Widget that splits Point input into two latitude/longitude boxes. """ def __init__(self, attrs=None, date_format=None, time_format=None): widgets = (forms.TextInput(attrs=attrs), forms.TextInput(attrs=attrs)) super(LatLongWidget, self).__init__(widgets, attrs) def decompress(self, value

django json serializer does not implement geojson

℡╲_俬逩灬. 提交于 2019-11-29 12:01:28
I am in the process of building a website on geodjango. On the front end I have a map on openlayers and I want to be able to fire ajax queries at some django url and get back geojson. The problem is that the standard django json serializer doesn't do geojson. So I have a model like: class Asset (models.Model): objects = models.GeoManager() url_name = models.CharField(max_length=200) name = models.CharField(max_length=200) point = models.PointField(srid=4326) def __unicode__(self): return self.name And I want to create a view: def geojson_query(request): #geographic query ... assets = Asset

3d distance calculations with GeoDjango

自作多情 提交于 2019-11-29 11:51:21
I am using python 2.7.12 django 1.10.6 postgreSQL 9.5.6 postGIS 2.2.2 First question I need to use GeoDjango to calculate distance between two points. When I checked the documentation it says that GeoQuerySet.distance() is deprecated and instead use Distance() from django.contrib.gis.db.models.functions . The following code works OK: from django.contrib.gis.db.models.functions import Distance p1 = Instrument.objects.get(pk=151071000).coordinates p2 = Instrument.objects.filter(pk=151071008) for i in p2.annotate(distance=Distance('coordinates', p1)): print i.distance print i.distance.__class__

GeoDjango on Windows: Try setting GDAL_LIBRARY_PATH in your settings

人盡茶涼 提交于 2019-11-29 09:34:26
问题 I've done this a dozen times before, but something isn't working this time.. Following the docs: https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/#windows I'm trying to set up GeoDjango on a Windows machine (this one is a virtual windows 10 set up on paperspace.com). There seems to be a problem with my PATH settings, but I can't figure out what it is. I've run the commands highlighted in the instructions. I've checked my PATH variables and everything seems ok. I've tried

Calculating distance between two points using latitude longitude and altitude (elevation)

99封情书 提交于 2019-11-29 02:46:22
I'm trying to calculate distance between two points, using latitude longitude and altitude (elevation). I was using euklides formula in order to get my distance: D=√((Long1-Long2)²+(Lat1-Lat2)²+(Alt1-Alt2)²) My points are geographical coordinates and ofcourse altitude is my height above the sea. I only have lat and lng, I'm using GOOGLE API Elevation to get my altitude. I'm developing an application which calculates my traveled distance (on my skis). Every application which I have used, gets distance traveled with included altitude. Like #Endomondo or #Garmin I cannot get my distance in 2D

GeoDjango distance filter with distance value stored within model - query

…衆ロ難τιáo~ 提交于 2019-11-29 02:32:26
问题 I have an Order model, that has an origin PointField and a range IntegerField. Furthermore, there is an UserProfile model, which has a geo_location PointField. Now, I have an User instance, user . I want to select all Orders , whose distance between Order.origin and user.userprofile.geo_location is less then the value (meters) in the Order.range model field. So again, simplified models: class Order(models.Model): origin = models.PointField() range = models.IntegerField(blank=True, default

How to assign to a Django PointField model attribute?

房东的猫 提交于 2019-11-29 00:47:25
问题 Hi I have a Django Model as follows: class Address(models.Model): geoCoords = models.PointField(null=True, blank=True,) Now I create an instance of this model: A = Address() How can I set the coordinates of A's geoCoord field to (5.3, 6.2)? I can't find any example of where a point field is assigned to in this way. It's such a stupidly simple question. Actually, the coordinates I would like to assign to A.geoCord are from pygeocoder. It is a 2-item tuple of floats. The documentation on Django

Calculate point based on distance and direction

人走茶凉 提交于 2019-11-28 19:01:16
I would like to calculate a point based on direction and distance using GeoDjango or GeoPy. For example, If I have a point that is (-24680.1613, 6708860.65389) I would like to find out a point 1KM North, 1KM East, 1KM Sourh and 1KM west using Vincenty distance formula. I closest thing I can find is a "destination" function in distance.py ( https://code.google.com/p/geopy/source/browse/trunk/geopy/distance.py?r=105 ). Although I cannot find this documented anywhere and I'm yet to figure out how to use it. Any help is much appreciated. Jan-Philip Gehrcke Edit 2 Okay, there is an out-of-the-box