Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region and Subregion model have no Geometry (area|location) - no way to query distance #183

Closed
4 of 5 tasks
kiddhustle opened this issue Nov 15, 2017 · 3 comments
Closed
4 of 5 tasks

Comments

@kiddhustle
Copy link

kiddhustle commented Nov 15, 2017

Checklist

  • I have verified that I am using a GIS-enabled database, such as PostGIS or Spatialite.
  • I have verified that that issue exists against the master branch of django-cities.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
from django.contrib.gis.db.models.functions import Distance
start_place = City.objects.filter(country__name='United Kingdom').get(name='London')

result = Region.objects.all().annotate(dist=Distance('location', start_place.location)).exclude(id=start_place.id).filter(name='Scotland').order_by('-dist')
or
```result = Region.objects.all().annotate(dist=Distance('location', start_place.location)).exclude(id=start_place.id).filter(name='Scotland').order_by('-dist')`

Expected behavior

To return the distance from Scotland region

Actual behavior

Following errors:

FieldError: Cannot resolve keyword 'location' into field. Choices are: alt_names, cities, code, country, country_id, id, name, name_std, postal_codes, slug, subregions
FieldError: Cannot resolve keyword 'area' into field. Choices are: alt_names, cities, code, country, country_id, id, name, name_std, postal_codes, slug, subregions
@blag
Copy link
Collaborator

blag commented Nov 17, 2017

Hi, thank you for reporting this, but this problem is actually much more complex than it might seem at a glance.

If you would like to have a point that represents a region or a subregion: where exactly do you want that point to be? The centroid of the region/subregion? What if that point is someplace far away from any city or sign of civilization? The capital of the region/subregion? Some places have multiple capitals - which one do I pick?

If you're trying to find the distance between two regions/subregions: which points do you want to use? The distance between the centroids? That wouldn't ever really be accurate. The distance between the closest points on each region/subregion? That also wouldn't ever be accurate. The distance between the farthest points on each region/subregion? Also wouldn't ever be accurate.

Really, representing an entire area as a point is the fundamental problem. I probably won't ever implement that for something as large as a region/subregion. There's simply no reasonable and generic way to represent an area as a point.

So lets talk about areas (or "boundaries" in GIS terminology). I would absolutely love to add boundaries to all of the models in the app! However, there isn't really a single good source for that data. Specifically I would like a single source that is:

  • international - only the US has very good maps (put out by the USGS - thank you!), the rest of the world has no good maps
  • accurate - I would like accurate sources
  • legally friendly - the terms and conditions for using some maps preclude them from use in this project - some sources may require payment, even to download or use a sample, or they may require the use of closed source or expensive software to use
  • consistent - one single file format

Furthermore, there is already a PR that attempts to implement this: #159.

Closing, because this is a duplicate of that. Please dig through the previously reported issues and pull requests before opening a new one.

@blag
Copy link
Collaborator

blag commented Nov 17, 2017

This also duplicates issue #125.

@kiddhustle
Copy link
Author

kiddhustle commented Nov 17, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants