PHPackages                             macs/geonames-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. macs/geonames-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

macs/geonames-bundle
====================

GeoNames.org geographical data and associated functionality

v2.0.2(5y ago)0619MITPHPPHP \*

Since Mar 18Pushed 5y agoCompare

[ Source](https://github.com/MindesignGCV/JJsGeonamesBundle)[ Packagist](https://packagist.org/packages/macs/geonames-bundle)[ RSS](/packages/macs-geonames-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (23)Used By (0)

Geonames Bundle
===============

[](#geonames-bundle)

Introduction
============

[](#introduction)

Provides access to the data exported by [geonames.org](http://geonames.org) into \[symfony 2\]\[sf2\] applications.

What is [geonames.org](http://geonames.org)
-------------------------------------------

[](#what-is-geonamesorg)

From the geonames.org website:

> The GeoNames geographical database covers all countries and contains over eight million placenames that are available for download free of charge.

When to use this bundle
-----------------------

[](#when-to-use-this-bundle)

Most useful application for this bundle is to normalize the geograhical information stored in your database such as Countries, States and Cities. Thanks to the extensive [geonames.org](http://geonames.org) data almost all cities, towns and suburbs are covered worldwide.

Features
--------

[](#features)

- Imports the following geonames.org data:

    - Countries
    - Timezones
    - States &amp; Provences
    - Cities, Towns, Suburbs, Villages etc.
- Provides the following data store implementations:

    - Doctrine ORM

Installation
============

[](#installation)

1. Install the bundle using composer:

    ```
    composer require jjs/geonames-bundle:*
    ```

    Or add it to your `composer.json` file directly

    ```
    {
        require: {
            "jjs/geonames-bundle": "*"
        }
    }
    ```
2. Add the bundle to your `AppKernel.php`

    ```
    // AppKernel::registerBundles()
    $bundles = array(
        // ...
        new JJs\Bundle\GeonamesBundle\JJsGeonamesBundle(),
        // ...
    );
    ```

Install or update database schema
---------------------------------

[](#install-or-update-database-schema)

The database schema for he bundle is defined using [doctrine migrations](http://symfony.com). Migration versioning is designed so they can be merged into your application migrations or migrate the schema manually.

### Independant versioning

[](#independant-versioning)

Execute the migrations using the supplied migration configuration

```
# Run in your project root directory
app/console doctrine:migrations:migrate --configuration=vendor/jjs/geonames-bundle/JJs/GeonamesBundle/migrations.xml
```

### Application versioning

[](#application-versioning)

This schema management stragegy involves more configuration and management, but comes with the benefit of greater control. It is possible due to mapping between incremental database version and semantic bundle version. It involves 'folding' the geonames schema versioning into your own migrations and managing the migration of your database as a whole.

As yet this versioning strategy is undocumented, please contact me if you're interested in using it and I will write the documentation.

Import the data
---------------

[](#import-the-data)

**Note** that importing the data from the remote geonames.org repository involves downloading almost 250 MB data from [geonames.org](http://geonames.org).

The following commands can be used in sequence to load all supported data from the [geonames.org](http://geonames.org) export ()

### Import countries

[](#import-countries)

Loads a list of all countries which are refenced by the other imported data such as timezones and localities.

```
app/console geonames:load:countries
```

### Import timezones

[](#import-timezones)

Loads a list of timezones mapped to countries

```
app/console geonames:load:timezones
```

### Filter localities

[](#filter-localities)

This fork allows you to filter localities that you want to import into your database.
**Note** This feature is little tested, use it at own risk.

#### Enable the filter

[](#enable-the-filter)

To use a filter, you have to specify the filter option `geonames:load:localities --filter="rule" [countries]`.
You might use several rules at once `geonames:load:localities --filter="rule,rule2" [countries]`.

### Add a filter rule

[](#add-a-filter-rule)

A filter rule consists of three parts:

- the value name
- the compare function
- the compare value
    `:` is used as an delemiter: `valuename:compare_func:compare_value`.

#### Value name

[](#value-name)

The value name is used to access a specific variable inside the Locality class.
It is internally converted to call the corresponding get function for that variable (`population` would be converted to `getPopulation`).
Only the first character of the value name will be converted to an upper-case letter,
so make sure that you check `Import/Locality.php` for the correct spelling of your get-function.

#### Compare function

[](#compare-function)

At this point you can use following functions:
To check if the value:
... is equal to the compare value (strings and integer) use `=`, `equal` or`equals`.
... is less or equal than the compare value (integer) use `=`.
... contains the compare value (string) use `contains`.

#### Examples

[](#examples)

Here are some examples:

```
# load all localities from germany with a population >= 2000
app/console geonames:load:localities --filter="population:>=:2000" DE

# load all localities with the locality-name "Kiel"
app/console geonames:load:localities --filter="nameUtf8:equals:Kiel"

# load all localities that contain "Test" in the locality-name
app/console geonames:load:localities --filter="nameUtf8:contains:Test"

# load all localities from germany with a population between 42000 and 100000
app/console geonames:load:localities --filter="population:>=:42000,population:
