请原谅我的无知,我甚至不确定这个的正确用语.我想要做的是在我的django应用程序中按城市和州或邮政编码搜索,还包括在该位置的某些距离内的结果(25,50,75英里).
我猜您可能需要将城市和州或邮政编码转换为lat和long,然后根据它进行搜索.这是正确的还是在django应用程序中实现这一目标的最佳方法是什么?有没有人知道退出已经执行此操作的应用程序,所以我可以查看代码?
谢谢您的帮助.
我正在使用GeoDjango中的形状文件.现在我正在尝试为加载在形状文件中的代码编写测试并将其保存到数据库中.形状文件目前的功能数量为64,118.我想将其减少到极少数,以便测试可以快速加载并确认一切正确.
由于形状文件不是文本格式,是否有一个免费的应用程序或库可以用来提取一些功能并将它们保存到新文件中?
我应该提到我没有许可证也无法访问任何ESRI产品系列.
我刚刚在我的开发机器上启动并运行GeoDjango.问题是我无法使距离查询正常工作.无论我使用什么SRID,距离结果都是完全关闭的.这是一个例子.
>>> from django.contrib.gis.measure import D
>>> from app.models import Place
>>> from django.contrib.gis.geos import Point
>>> qs = Place.objects.all()
>>> point = Point(-118, 34)
>>> qs.filter(coordinates__distance_lte=(point, D(m=1)))
[<Place: 7-Eleven>, <Place: Arthur Murray Dance Studio>, <Place: Costco>, <Place: AMC Century City 15>, <Place: 24 Hour Fitness>, <Place: Ralphs>, <Place: Houston's Restaurant>, <Place: CVS/pharmacy>, <Place: Shaky Alibi>, <Place: Sephora>, <Place: Trader Joe's>]
Run Code Online (Sandbox Code Playgroud)
问题是这些地方远离1米远point.
我试着玩弄它,但运气不好.这是另一个SRID的示例.
>>> qs = Place.objects.all().transform(3786)
>>> point = Point(-118, 34, srid=3786)
>>> qs.filter(coordinates__distance_lte=(point, D(m=1)))
[<Place: 7-Eleven>, …Run Code Online (Sandbox Code Playgroud) 我有这两个型号.
class Store(models.Model):
coords = models.PointField(null=True,blank=True)
objects = models.GeoManager()
class Product(models.Model):
stores = models.ManyToManyField(Store, null=True, blank=True)
objects = models.GeoManager()
Run Code Online (Sandbox Code Playgroud)
我想让产品按距离分类.如果Product中的stores字段是外键,我会这样做并且它可以工作.
pnt = GEOSGeometry('POINT(5 23)')
Product.objects.distance(pnt, field_name='stores__coords').order_by('distance')
Run Code Online (Sandbox Code Playgroud)
但由于该字段是ManyToMany字段,它打破了
ValueError: <django.contrib.gis.db.models.fields.PointField: coords> is not in list
Run Code Online (Sandbox Code Playgroud)
我有点期待这个,因为它不清楚应该用哪个商店来计算距离,但有没有办法做到这一点.
我需要按距离排序到特定点的产品列表.
我在Heroku上收到以下错误:
django.core.exceptions.ImproperlyConfigured: Could not import user-defined GEOMETRY_BACKEND "geos".
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为它之前有效.
我将buildpack设置为https://github.com/dulaccc/heroku-buildpack-geodjango/.
在我的settings.py中,我有:
GEOS_LIBRARY_PATH = environ.get('GEOS_LIBRARY_PATH')
GDAL_LIBRARY_PATH = environ.get('GDAL_LIBRARY_PATH')
Run Code Online (Sandbox Code Playgroud)
当我部署到Heroku时,它似乎找到了GEOS.这是日志:
-----> Checking for GEOS
Installed
GEOS installed and accessible with env variable 'GEOS_LIBRARY_PATH'
-----> Checking for Proj.4
Installed
Proj.4 installed and accessible with env variable 'PROJ4_LIBRARY_PATH'
-----> Checking for GDAL
Installed
GDAL installed and accessible with env variable 'GDAL_LIBRARY_PATH'
Run Code Online (Sandbox Code Playgroud) 我刚刚使用最新版本的KyngChaos库在OSX Mavericks上安装了Postgres 9.3.4和PostGIS 2.1 .
但是,当我尝试在数据库上创建空间扩展时,我不能,因为Postgres声称无法看到扩展文件:
:~ anna$ psql -d land -c "CREATE EXTENSION postgis;"
ERROR: could not open extension control file
"/usr/local/Cellar/postgresql/9.3.4/share/postgresql/extension/postgis.control":
No such file or directory
Run Code Online (Sandbox Code Playgroud)
看起来该文件位于其他位置:
:~ anna$ mdfind postgis.control
/usr/local/pgsql-9.3/share/extension/postgis.control
Run Code Online (Sandbox Code Playgroud)
我肯定使用Postgres的预期版本,虽然我不知道这是否是KyngChaos库通常安装的地方:
Annas-MacBook-Air:~ anna$ psql --version
psql (PostgreSQL) 9.3.4
Annas-MacBook-Air:~ anna$ which psql
/usr/local/pgsql-9.3/bin/psql
Run Code Online (Sandbox Code Playgroud)
我一直非常小心不使用Homebrew等安装Postgres,因为我知道它会导致同一系统的多个版本出现问题.
任何人都可以建议扩展文件为什么不在预期的位置?
更新:
看起来可能在我的系统上有多个版本的Postgres浮动,我使用的是错误的版本?
:~ anna$ mdfind -name "postgres" | grep -G "postgres$"
/usr/local/pgsql-9.3/bin/postgres
/usr/local/var/postgres
/usr/local/Cellar/postgresql/9.3.4/bin/postgres
Run Code Online (Sandbox Code Playgroud)
我应该使用哪一个,如何设置系统默认使用这个?
进一步更新
这是输出pg_config:
BINDIR = /usr/local/pgsql-9.3/bin
DOCDIR = /usr/local/pgsql-9.3/share/doc
INCLUDEDIR = /usr/local/pgsql-9.3/include
PKGINCLUDEDIR …Run Code Online (Sandbox Code Playgroud) Profile包含一个PointField.我在ProfileAdmin中使用过OSMGeoAdmin,这里:
class ProfileAdmin(admin.OSMGeoAdmin):
model = Profile
Run Code Online (Sandbox Code Playgroud)
但无法弄清楚如何在内联中使用它在UserAdmin中显示.我目前的设置如下:
# User Admin, with Profile attached
class ProfileInline(admin.StackedInline):
model = Profile
can_delete = False
verbose_name_plural = 'Profile' # As only one is displayed in this view
class UserAdmin(UserAdmin):
inlines = (
ProfileInline,
)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
Run Code Online (Sandbox Code Playgroud)
在这种情况下是否可以使用类OSMGeoAdmin?
我有以下型号:
class Stop(models.Model):
name = models.CharField(max_length=50)
point = models.PointField()
objects = models.GeoManager()
Run Code Online (Sandbox Code Playgroud)
我想从北到南排序.我该怎么做呢?
Stop.objects.order_by('point')他们从西向东排序.
谢谢.
这是我的完整模型:
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
class Stop(models.Model):
gtfs_stop_id = models.IntegerField(db_index=True, unique=True)
name = models.CharField(max_length=50)
point = models.PointField()
parkings = models.GeometryCollectionField(null=True, blank=True)
objects = models.GeoManager()
def get_absolute_url(self):
return reverse('core:stop', args=(self.id,))
def __str__(self):
return self.name
Run Code Online (Sandbox Code Playgroud) Django v1.11.5
我正在尝试安装GeoDjango来玩GoogleMaps.
我为MAC安装了PostgreSQL应用程序并安装了pip install psycopg2.我还用home-brew来安装GDAL.
编辑settings.py添加:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'djangodb',
'USER': 'admin',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行python manage.py迁移时,我得到:AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
我创建了用户:CREATE DATABASE djangodb OWNER admin;
完全错误:
正在运行迁移:应用users.0011_location ... Traceback(最近一次调用最后一次):文件"manage.py",第22行,在execute_from_command_line(sys.argv)文件"/ Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/init .py",第364行,在execute_from_command_line utility.execute()文件"/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site- packages/django/core/management/init .py",第356行,执行self.fetch_command(子命令).run_from_argv(self.argv)文件"/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/ site-packages/django/core/management/base.py",第283行,在run_from_argv中自执行(*args,**cmd_options)文件"/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/ site-packages/django/core/management/base.py",第330行,执行输出= self.handle(*args,**options)文件"/ Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3. 6/site-packages/django/core/management/commands/migrate.py",第2行 04,处理fake_initial = fake_initial,文件"/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py",第115行,处于migrate state = self ._migrate_all_forwards(state,plan,full_plan,fake = fake,fake_initial = fake_initial)文件"/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py" ,第145行,在_migrate_all_forwards state = self.apply_migration(state,migration,fake = fake,fake_initial …
我设置了一个当前为空的Geodjango应用程序-我已连接到Postgis数据库,在该数据库中我有一个名为aadf的表,试图从中创建模型。我正在使用inspectdb来做到这一点。
我收到以下错误消息:
from django.contrib.gis.db import models
# Unable to inspect table 'aadf'
# The error was: sequence index must be integer, not 'slice'
# Unable to inspect table 'auth_group'
# The error was: sequence index must be integer, not 'slice'
# Unable to inspect table 'auth_group_permissions'
# The error was: sequence index must be integer, not 'slice'
** This error message repeats for multiple other tables that Django has created **
Run Code Online (Sandbox Code Playgroud)
与数据库的连接显然很不错,因为它可以获取相关的表名。也就是说,它似乎还试图检查Django在数据库中创建的其他表,例如“ …
geodjango ×10
django ×8
postgresql ×3
python ×3
postgis ×2
django-2.2 ×1
django-admin ×1
django-orm ×1
geolocation ×1
gis ×1
heroku ×1
shapefile ×1