-
Notifications
You must be signed in to change notification settings - Fork 374
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
Models - point vs area #125
Comments
As far as I'm aware, PointField do make use of GIS enabled databases, although we do support databases without GIS support (in which case we use a simple hypotenuse calculation to figure out the closest encompassing feature).
My assumption is the centroid of the polygon of the feature, but that would be best answered by Geonames. The PointField is calculated from the latitude and longitude fields from the Geonames dump.
You can find more information from:
I would definitely accept a PR that added a BoundaryField and imported the polygon data from Geonames. It would probably be easiest to use their shapes_simplified_low.json.zip and use Python's geojson package to import the boundaries for the features we already import. |
Fair enough. I am geofencing and need to have the polygons for more exact tracking. If I can keep this issue open for a while I will see if we can bring in the boundary/topology data. |
@solvire Sure, we can keep this issue open. 😄 |
The project is paused so if I can't get a proposition in within a month I'll go ahead an update. |
Hello all! Boundaries would rock. I also need them for a bunch of other things, like determining if a point belongs to a certain city. I'll see what I can do to create PR. |
@george-silva Let me know if you have any questions or need any help. This would be a fantastic addition. |
@blag I still haven't had time to work on this, but I might this week. Looking forward to this. If this is done I can ditch the other package I work with for cities and use just this one. Thanks! |
I'm curious: what other package are you using in conjunction with this one? And I'm in the middle of a job hunt, so I probably won't be much use to you (in terms of writing code) for a few weeks. I'll try to review code for you though. Thanks for taking this on! 👍 ❤️ |
@blag I'm using django-municipios, which is Brazil only. No problem. The code review will be valuable. |
I'm glad that django-municipios exists, but too bad is Brazil only. Are the shapefiles that django-municipios imports supplied by users or does it import shapefiles from somewhere? I've been thinking about how I would implement this feature for a few weeks, here's some things I would consider:
Don't let any of these confuse you or frighten you off - deal with them as issues come up. And feel free to ping me if you have any questions or anything. |
Hello @blag. Let me respond to you point by point. First of all:
I'm targeting PostGIS as the gold standard. And the field already is a MultiPolygon. It should be a MultiPolygon to support countries with islands, for example.
For now, this won't be a problem and SQLite will be supported. There are no differences in Django for creating/editing geometry fields. What we will need to do is to create specific settings to test all the tests against SQLite. I use GitLab at our shop so we have a different method for running two sets of tests (postgresql/sqlite), but we do have two different settings. This can be fairly easy to accomplish as well.
I already did that 😄 .
True. First of all we need a source. For countries and continents it's fairly. I don't know any source for city boundary on a global scale. Perhaps OSM can be useful for that.
Will take extra care with that.
Already nullable as well.
Ok.
Ok.
The fields needs to be GEOMETRY, otherwise it won't have support in Oracle or Sqlite. So that's a no brainer. Already geometry as well.
MultiPolygon is the correct way to go. Since we already require PostGIS for the location field, I would not worry too much about the native Polygon datatype (I did not see any reference to the native datatype in the project, perhaps I'm wrong).
I really don't think this belongs to the scope of this project. These boundaries rarely change and the users might care more about the most updated one, instead of a history of boundaries. I'm already developing some code and the modifications for the fields is already there. As I said, I'm running into issues on how to run makemigrations. If you have any tips on that, let me know. |
Oh awesome, I didn't realize you already had written code!
Right! And states like Michigan can only accurately be represented as MultiPolygons. I didn't realize Michigan also had islands as well.
The GIS contrib app distributed with Django (
I agree, I only bring it up because I don't want to prevent users from implementing that themselves. I want this to be possible only by overriding one of our concrete models and configuring django-field-history instead of forking this project altogether. Hope that makes sense.
You might be able to use the management command in PYTHONPATH=. python test_project/manage.py makemigrations cities and see if that works for you. However, what I'm actually doing is using one of my Django projects to make the migrations for this app. It's a little complicated, but it works for me. My project directory structure looks like:
then I can run |
The PYTHONPATH trick worked fine. I'll soon post the model changes and the migration, so you can take a look. The download of the boundary data is way more involved and I'll take it slow. I need to first identify a good source of data for State/City. Continents and Countries are easy. Regarding the CLI option, I think we will need to make another switch. Thats because you can download countries AND it's boundaries. Or you might download countries, regions and cities, and it's boundaries. Or you just care about the city boundaries (because the sum of all cities are regions and the sum of all regions are countries, etc). So perhaps we can make this available for each model? I should be committing to my fork soon and I'll ping you for a quick review. I'm just installing Py3.6 so we can run tox on it as well. Some of the tests are failing because I don't have all environments (all tests pass on 2.7). |
This is great you are pushing it along @george-silva |
City boundaries using multi-polygon would be great. @george-silva could you push even incomplete code to a fork? I may be able to find time to help this feature happen. |
Hi @merwok - glad others are taking interest... |
FWIW: In a previous project I rolled my own simple classes for City and Address (didn’t need country or region), with only PostGIS supported (so PointField and MultiPolygonField without compat concerns) and getting some information from Google Maps and from a GeoJSON file published by my city; geo queries worked like a charm. For a new project we wanted to rely on OSM/geonames and standardize on django-cities, so right now we decided we prefer to avoid forking the repo, and we’ll have the multi-polygon field in a custom model linked to cities.City. I can’t spend days on an upstream PR, but if I could be able to contribute things such as manager tests, an import command. |
That seems like a very sane way to go about it. Custom models were not working for me though so I had to abandon and did a separate model with OneToOne field. Not ideal. |
(Exactly, I meant a separate model with one to one when I said “custom model linked”, given that swapped-in custom models don’t work at the moment) |
I Just left the office. I'm pretty sure I already have a chance and a small
PR in Github.
When I get home ill find It and pass It along.
It only has the changes to the model.
We need now is to download reliable data for It. Im Sorry this got
sidetracked but more urgent things came along.
I'm here to help 😀
Em 16 de jun de 2017 3:15 PM, "Éric Araujo" <[email protected]>
escreveu:
… (Exactly, I meant a separate model with one to one when I said “custom
model linked”, given that swapped-in custom models don’t work at the moment)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#125 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA0rP77VPYN-VKSjQCvPbSeIqtGgdpasks5sEsZMgaJpZM4JWsmi>
.
|
I'm pretty sure @george-silva already pushed his changes to PR #159. It's incomplete, but it's a start. |
Hello all. this is my fork: https://github.com/sigma-geosistemas/django-cities In there you'll find the updated models. What we need help right now is defining the "sources of truth" for each entity (country, city, continent, etc) and to create the utility to download all of this data and update it. This is the full discussion: #159 |
I noticed the models have a PointField instead of a polygon
Is there a good strategy in the future to make use of GIS enabled databases or the GeoDjango features?
Also if this is a point field what is the point in reference to?
The text was updated successfully, but these errors were encountered: