Skip to content

Query geographic reference data more easily.

License

Notifications You must be signed in to change notification settings

cvilleger/geo-gouv

Repository files navigation

GitHub Actions Workflow Status Packagist Version Packagist Downloads GitHub License

cvilleger/geo-gouv

About

Query geographic reference data more easily using offline data from Gouv administrative division API.

Features

  • Query all departments data
  • Query all municipalities by department code

Requirements

cvilleger/geo-gouv requires at least PHP 8.2

Installation

Install this package as a dependency using Composer.

composer require cvilleger/geo-gouv

Usage

Retrieve all departments

use Cvilleger\GeoGouv\Client;

$client = new Client();

$departements = $client->getDepartements();

print_r($departements[0]);
/*
Cvilleger\GeoGouv\Model\Departement Object
(
    [nom] => Ain
    [code] => 01
    [codeRegion] => 84
    [region] => Cvilleger\GeoGouv\Model\Region Object
        (
            [nom] => Auvergne-Rhône-Alpes
            [code] => 84
        )

)
*/

Retrieve all municipalities by department code

use Cvilleger\GeoGouv\Client;

$client = new Client();

$communes = $client->getCommunesByDepartementCode('01');

print_r($communes[0]);
/*
(
    [nom] => L'Abergement-Clémenciat
    [code] => 01001
    [codesPostaux] => Array
        (
            [0] => 01400
        )

    [centre] => Cvilleger\GeoGouv\Model\Centre Object
        (
            [type] => Point
            [coordinates] => Array
                (
                    [0] => 4.9306
                    [1] => 46.1517
                )

        )

    [surface] => 1564.5
    [population] => 832
    [departement] => Cvilleger\GeoGouv\Model\CommuneDepartement Object
        (
            [nom] => Ain
            [code] => 01
        )

    [region] => Cvilleger\GeoGouv\Model\CommuneRegion Object
        (
            [nom] => Auvergne-Rhône-Alpes
            [code] => 84
        )

)
*/