Skip to content

Countries and cities of the world for Django projects

License

Notifications You must be signed in to change notification settings

lecs/mongo-cities

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongo-cities - Place models and data for MongoEngine
====================================================

Based on the django-cities project by Ben Dowling.

    - models: the models part has been migrated to use MongoEngine
    - fixtures_to_mongo: a little management command imports the
      fixtures provided within the project.

The data is originally provided by GeoNames:
    - http://download.geonames.org/export/dump/countryInfo.txt
    - http://download.geonames.org/export/dump/admin1CodesASCII.txt
    - http://download.geonames.org/export/dump/cities1000.zip

Includes 234 counties, 2,610 regions, 97,949 cities and 606 districts

For more information and examples regarding the original django-cities see
http://www.coderholic.com/django-cities-countries-regions-cities-and-districts-for-django/


Importing the fixtures:
=======================

Import everthing

>>> ./manage.py fixtures_to_mongo

Import all objects for Luxembourg and Liechtenstein

>>> ./manage.py fixtures_to_mongo LU,LI


Querying:
=========

Finding all London boroughs:

>>> uk = Country.objects.get(code='GB')
>>> london = City.objects.get(name='London', country=uk)
>>> boroughs = District.objects.filter(city=london)

Nearest city to a given lon, lat:

>>> lonlat = ((51, 1))
>>> City.nearest(lonlat)
<City: Dymchurch, Kent, United Kingdom>

Distance of Berlin to a given lat, lon:

>>> berlin = City.objects.get(name='Berlin')
>>> lonlat_of_NY = ((-73.96751403808594, 40.78054143186031))
>>> berlin.distance_to(lonlat_of_NY)
6384.579236572246

Distance of Berlin to London:

>>> berlin.distance_to(london)
932.8145043305717

5 Nearest cities to London:

>>> City.near(london.location).filter(id__ne=london.id).order_by('distance')[:5]

About

Countries and cities of the world for Django projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%