GithubHelp home page GithubHelp logo

stringfellow / mongo-cities Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lecs/mongo-cities

1.0 1.0 0.0 10.98 MB

Countries and cities of the world for Django projects

License: MIT License

Python 100.00%

mongo-cities's Introduction

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]

mongo-cities's People

Contributors

coderholic avatar shanto avatar georgema1982 avatar riz avatar

Stargazers

Steve Pike avatar

Watchers

Steve Pike avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.