Django GIS:使用 location__dwithin 给出 "Only numeric values of degree units are allowed" 但是 location__distance_lte 工作正常
Django GIS : Using location__dwithin gives "Only numeric values of degree units are allowed" however location__distance_lte works fine
我有以下两个问题。第一个工作正常但是最后一个使用 location__dwithin
returns 返回 Unable to get repr for 。关于最后一个失败的原因有什么建议吗?
querySet = modelEmployee.objects.filter(location__distance_lte=(modelemp.location, D(mi=150)))
另一个是:
querySet = modelEmployee.objects.filter(location__dwithin=(modelemp.location, D(mi=150)))
这就是我的 modelEmployee 的样子
class modelEmployee(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
title = models.CharField(max_length=200, unique=False, blank=False, null=True)
skills = models.ManyToManyField(modelSkill, blank=True)
location = models.PointField(srid=32148,max_length=40, blank=True,null=True)
objects = GeoManager()
def __str__(self):
return "Employee name : " + self.user.first_name
我得到的错误是这个
raise ValueError('Only numeric values of degree units are '
ValueError: Only numeric values of degree units are allowed on geographic DWithin queries
.
这是回溯
Traceback (most recent call last):
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/channels/handler.py", line 243, in process_exception_by_middleware
return super(AsgiHandler, self).process_exception_by_middleware(exception, request)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/TestWeb/Employer/views.py", line 42, in post
employeesJson = Serializer_Employee_TX(querySet,many=True,context={"request": request,shared.LOGGED_IN_EMPLOYER_SHARED:modelemp}).data
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 765, in data
ret = super(ListSerializer, self).data
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 262, in data
self._data = self.to_representation(self.instance)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 683, in to_representation
self.child.to_representation(item) for item in iterable
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 268, in __iter__
self._fetch_all()
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 1186, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1052, in execute_sql
sql, params = self.as_sql()
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 464, in as_sql
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 390, in compile
sql, params = node.as_sql(self, self.connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 390, in compile
sql, params = node.as_sql(self, self.connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 78, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 307, in process_rhs
dist_sql, dist_params = self.process_distance(compiler, connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 297, in process_distance
('%s', connection.ops.get_distance(self.lhs.output_field, self.rhs_params, self.lookup_name))
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 264, in get_distance
raise ValueError('Only numeric values of degree units are '
ValueError: Only numeric values of degree units are allowed on geographic DWithin queries.
[2018/10/31 00:24:31] HTTP POST /api/employer/login/ 500 [8.10, 127.0.0.1:58046]
来自docs:
Note that you can only provide Distance objects if the targeted
geometries are in a projected system. For geographic geometries, you
should use units of the geometry field (e.g. degrees for WGS84) .
尝试:
querySet = modelEmployee.objects.filter(location__dwithin=(modelemp.location, 1))
我有以下两个问题。第一个工作正常但是最后一个使用 location__dwithin
returns 返回 Unable to get repr for 。关于最后一个失败的原因有什么建议吗?
querySet = modelEmployee.objects.filter(location__distance_lte=(modelemp.location, D(mi=150)))
另一个是:
querySet = modelEmployee.objects.filter(location__dwithin=(modelemp.location, D(mi=150)))
这就是我的 modelEmployee 的样子
class modelEmployee(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
title = models.CharField(max_length=200, unique=False, blank=False, null=True)
skills = models.ManyToManyField(modelSkill, blank=True)
location = models.PointField(srid=32148,max_length=40, blank=True,null=True)
objects = GeoManager()
def __str__(self):
return "Employee name : " + self.user.first_name
我得到的错误是这个
raise ValueError('Only numeric values of degree units are '
ValueError: Only numeric values of degree units are allowed on geographic DWithin queries
.
这是回溯
Traceback (most recent call last):
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/channels/handler.py", line 243, in process_exception_by_middleware
return super(AsgiHandler, self).process_exception_by_middleware(exception, request)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/admin/Development/TestWeb/virtual/TestWeb/Employer/views.py", line 42, in post
employeesJson = Serializer_Employee_TX(querySet,many=True,context={"request": request,shared.LOGGED_IN_EMPLOYER_SHARED:modelemp}).data
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 765, in data
ret = super(ListSerializer, self).data
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 262, in data
self._data = self.to_representation(self.instance)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/rest_framework/serializers.py", line 683, in to_representation
self.child.to_representation(item) for item in iterable
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 268, in __iter__
self._fetch_all()
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 1186, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1052, in execute_sql
sql, params = self.as_sql()
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 464, in as_sql
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 390, in compile
sql, params = node.as_sql(self, self.connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 390, in compile
sql, params = node.as_sql(self, self.connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 78, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 307, in process_rhs
dist_sql, dist_params = self.process_distance(compiler, connection)
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/models/lookups.py", line 297, in process_distance
('%s', connection.ops.get_distance(self.lhs.output_field, self.rhs_params, self.lookup_name))
File "/Users/admin/Development/TestWeb/virtual/lib/python3.5/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 264, in get_distance
raise ValueError('Only numeric values of degree units are '
ValueError: Only numeric values of degree units are allowed on geographic DWithin queries.
[2018/10/31 00:24:31] HTTP POST /api/employer/login/ 500 [8.10, 127.0.0.1:58046]
来自docs:
Note that you can only provide Distance objects if the targeted geometries are in a projected system. For geographic geometries, you should use units of the geometry field (e.g. degrees for WGS84) .
尝试:
querySet = modelEmployee.objects.filter(location__dwithin=(modelemp.location, 1))