使用geoDjango,有什么区别
myObj.objects.filter(point__dwithin(...etc.))
Run Code Online (Sandbox Code Playgroud)
和
myObj.objects.filter(point__distance_lt(...etc.))
Run Code Online (Sandbox Code Playgroud)
?
它们是同一个东西,还是它们做着微妙不同的事情?
我一直在使用django和mysql开发应用程序,我现在正在尝试从这里开始学习这个教程
http://docs.djangoproject.com/en/1.2/ref/contrib/gis/tutorial/
但是当我运行syncdb时出现以下错误,它失败了
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
Run Code Online (Sandbox Code Playgroud)
当我阅读时,它说如果改变后端使用postGIS,这可以解决.有没有办法继续使用mysql作为我的后端,但能够使用geodjango?如果没有,是否可以在同一个项目中使用它们?
问候,
我试图让GeoDjango在ubuntu上运行并且遇到了GDAL的问题.
我已经下载并安装了GDAL而没有任何问题.
我必须在项目设置中添加以下行:
GDAL_LIBRARY_PATH = '/usr/local/lib/libgdal.so.1.15.1'
Run Code Online (Sandbox Code Playgroud)
当我签入shell时一切都很好:
In [1]: from django.contrib.gis import gdal
In [2]: gdal.HAS_GDAL
Out[2]: True
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在官方教程中运行ogrinfo时,我收到以下错误:
$ ogrinfo world/data/TM_WORLD_BORDERS-0.3.shp
ogrinfo: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
GDAL文件位于:
/usr/local/lib/libgdal.a
/usr/local/lib/libgdal.la
/usr/local/lib/libgdal.so
/usr/local/lib/libgdal.so.1
/usr/local/lib/libgdal.so.1.15.1
Run Code Online (Sandbox Code Playgroud)
libgdal.so
和libgdal.so.1
符号链接到libgdal.so.15.1
任何帮助将非常感激.
您好我想知道如何使用Docker将POSTGIS连接到django.我有一个错误could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory
产量
root@localhost:~/try-geodjango# docker-compose run web python manage.py migrate
Starting try-geodjango_db_1 ... done
/usr/local/lib/python3.5/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.OperationalError: could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or …
Run Code Online (Sandbox Code Playgroud) 我想使用管理命令对马萨诸塞州的建筑物进行一次性分析.我已经将违规代码减少为8行代码片段,演示了我遇到的问题.评论只是解释了为什么我要这样做.我在一个空白的管理命令中逐字地运行下面的代码
zips = ZipCode.objects.filter(state='MA').order_by('id')
for zip in zips.iterator():
buildings = Building.objects.filter(boundary__within=zip.boundary)
important_buildings = []
for building in buildings.iterator():
# Some conditionals would go here
important_buildings.append(building)
# Several types of analysis would be done on important_buildings, here
important_buildings = None
Run Code Online (Sandbox Code Playgroud)
当我运行这个确切的代码时,我发现内存使用量随着每个迭代外部循环而稳定增加(我print('mem', process.memory_info().rss)
用来检查内存使用情况).
important_buildings
即使在超出范围之后,列表似乎也会占用内存.如果我替换important_buildings.append(building)
它_ = building.pk
,它不再消耗大量内存,但我确实需要该列表进行一些分析.
所以,我的问题是:当它超出范围时,如何强制Python发布Django模型列表?
编辑:我觉得堆栈溢出有一点问题 - 如果我写了太多细节,没有人想花时间阅读它(它变成一个不太适用的问题),但如果我写得太少细节,我冒险忽略部分问题.无论如何,我真的很感激答案,并计划在本周末尝试一些建议,当我终于有机会回到这里!
我刚刚在GeoDjango上开始了我的第一个项目.
事实上,使用GeoDjango支持的管理应用程序,我们都很有可能查看/编辑与当前对象相关的空间数据.
问题是在填充对象后,我需要在一个地图上一次渲染多个对象的关联几何体.我可以将其实现为模型操作,重定向到自定义视图.我只是不知道,如何在视图中包含OpenLayers小部件以及如何在我的GeoQuerySet中渲染我的复合几何.
我非常感谢来自经验丰富的GeoDjango程序员的任何暗示.
我正在使用GEOS API中的"缓冲"方法根据GeoDjango中的点和半径创建一个圆,根据这个答案:GeoDjango:如何根据点和半径创建一个圆
正如一位评论者指出的那样,你必须将半径以km为单位转换为......但是如何?我想这是一个快速的公式,但它对我来说是希腊语.我会感激任何指针.
尝试启动django服务器时,出现以下错误:
django.core.exceptions.ImproperlyConfigured: Could not import user-defined GEOMETRY_BACKEND "geos".
Run Code Online (Sandbox Code Playgroud)
我在Mac OS Lion上运行postgresql8.4.
我用Macports来安装PostGIS.这是$ port安装显示的内容:
postgis @ 1.5.2_1 + postgresql84 postgis @ 1.5.2_1 + postgresql90 postgis @ 1.5.3_0 + postgresql90 postgis @ 1.5.3_0 + postgresql91(active)
这是我在尝试确定我所拥有的PostGIS版本时得到的结果:
geodjango=# SELECT PostGIS_full_version();
ERROR: could not access file "$libdir/postgis-1.5": No such file or directory
CONTEXT: SQL statement "SELECT postgis_lib_version()"
PL/pgSQL function "postgis_full_version" line 11 at SQL statement
Run Code Online (Sandbox Code Playgroud) 嗨Stackoverflow人,
我用GeoDjango做了我的第一步,我正在寻找更好的选项来检查错误的sql语句.
到目前为止,我只是想在postgresql表中保护lng + lat点.
该模型定义为:
geolocation = models.PointField(_('Geo Location'),
geography=True,
null = True,
blank = True,
help_text=_('Geolocation with Longitude and Latitude'))
objects = models.GeoManager()
Run Code Online (Sandbox Code Playgroud)
在我看来,我尝试执行以下命令
savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))
Run Code Online (Sandbox Code Playgroud)
但是当我尝试保存表单时收到以下错误:
异常类型:InternalError异常值:当前事务被中止,命令被忽略,直到事务块结束
这个错误的原因是什么?我相信sql语句可能有问题,但检查的最佳方法是什么?Django只提供一般错误消息"内部错误".
感谢您的帮助和建议!
我有一个Order
模型,它有一个origin
PointField和一个range
IntegerField.此外,还有一个UserProfile
模型,它有一个geo_location
PointField.现在,我有一个User
实例,user
.我想选择所有Orders
,其之间的距离Order.origin
,并user.userprofile.geo_location
在小于该值(米)的Order.range
示范田.
再次简化模型:
class Order(models.Model):
origin = models.PointField()
range = models.IntegerField(blank=True, default=10000)
class UserProfile(models.Model):
geo_location = models.PointField()
Run Code Online (Sandbox Code Playgroud)
我有这个工作(静态通过距离):
>>> Order.objects.filter(origin__distance_lte=(user.profile.geo_location, D(m=3000)))
Run Code Online (Sandbox Code Playgroud)
我的下一个(不成功)尝试是使用F()表达式来使用Order.range
字段中的值:
>>> Order.objects.filter(origin__distance_lte=(user.profile.geo_location, D(m=F('range'))))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/danger/devel/.virtualenvs/proj/lib/python2.7/site-packages/django/contrib/gis/measure.py", line 165, in __init__
self.m, self._default_unit = self.default_units(kwargs)
File "/Users/danger/devel/.virtualenvs/proj/lib/python2.7/site-packages/django/contrib/gis/measure.py", line 49, in default_units
if not isinstance(value, …
Run Code Online (Sandbox Code Playgroud) geodjango ×10
django ×9
python ×5
postgresql ×2
docker ×1
gdal ×1
geospatial ×1
gis ×1
macos ×1
openlayers ×1
postgis ×1
view ×1