crovitche / swiss-geo-bundle
Import swiss building addresses, streets and localities locally on your MySQL database using Doctrine ORM
Installs: 968
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.13 || ^3.0
- guzzlehttp/guzzle: ^7.7
- http-interop/http-factory-guzzle: ^1.0
- league/csv: ^9.7
- meilisearch/meilisearch-php: ^1.5
- symfony/cache: ^6.4|^7.0
- symfony/config: ^6.4|^7.0
- symfony/console: ^6.4|^7.0
- symfony/dependency-injection: ^6.4|^7.0
- symfony/filesystem: ^6.4|^7.0
- symfony/finder: ^6.4|^7.0
- symfony/form: ^6.4|^7.0
- symfony/http-client: ^6.4|^7.0
- symfony/http-foundation: ^6.4|^7.0
- symfony/lock: ^6.4|^7.0
- symfony/monolog-bundle: ^3.7
- symfony/options-resolver: ^6.4|^7.0
- symfony/yaml: ^6.4|^7.0
Requires (Dev)
Suggests
- ext-curl: *
This package is auto-updated.
Last update: 2024-11-05 10:57:12 UTC
README
SwissGeoBundle provide you a clean way to use swiss building addresses. If you have the following use cases, this bundle can be useful for you :
- An autocomplete address input without incorrect address entries
- Store addresses locally (offline !)
- "I want to locate my clients on a map offline."
- Create statistics based on addresses:
- "In which locality do I have the majority of my customers?"
- Avoid Google Map services and therefore save money
- Avoid having postal addresses that are no longer valid.
- "How can this customer live here? This building has been destroyed!"
- Get some information about addresses:
- "Is this building partly residential ?"
- "Is this address on a street or a place?"
- "Is this address already built or planned ?"
- ...
Technical requirements
SwissGeoBundle requires the following:
- MySQL 8.0 or higher (other RDBMS coming soon...) with this options activated:
- PHP 8.1 or higher
- Symfony components specified in
composer.json
- Doctrine ORM entities (Doctrine ODM is not supported)
- Meilisearch v1.5 - Necessary for full address search (performance too low otherwise)
version: '3.7' services: meilisearch: hostname: meilisearch image: getmeili/meilisearch:v1.5 environment: - MEILI_ENV=development # set the max payload to 200Mb instead of 100 default one # addresses file is around 170Mb - MEILI_HTTP_PAYLOAD_SIZE_LIMIT=209715200 - MEILI_NO_ANALYTICS=true ports: - '7701:7700' networks: - network volumes: - meilisearch-data:/data.ms restart: unless-stopped
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
composer require crovitche/swiss-geo-bundle
Then make sure the bundle is enabled in registered bundles in
config/bundles.php
if your application doesn't use Symfony Flex.
Getting started
Run the following commands and put them in a cron if you want your data to be updated regularly.
1. Configure your entity
<?php declare(strict_types=1); namespace App\Entity; use Crovitche\SwissGeoBundle\Entity\BuildingAddress; use Doctrine\ORM\Mapping as ORM; //... #[ORM\Entity(CustomerRepository::class), ORM\Table("Customer")] #[ORM\Index(columns: ["egaid"], name: "IX___Customer___building_address")] class Customer { //... #[ORM\ManyToOne(BuildingAddress::class)] #[ORM\JoinColumn("egaid", "egaid", false, true, "SET NULL")] private ?BuildingAddress $postalAddress = null; }
2. Create a database migration.
To do this, you have to use DoctrineMigrationBundle.
Generate a migration using Maker bundle.
php bin/console make:migration
This command will automatically generate the SQL you in a migration php file.
Check the created migration and add this piece of code if it does not exist :
public function up(Schema $schema): void { // ... $this->addSql(/** @lang MySQL */' ALTER TABLE Building_address ADD CONSTRAINT CK___Building_address___building_name__xor__address_number CHECK ((building_name IS NOT NULL XOR address_number IS NOT NULL) OR (building_name IS NULL AND address_number IS NULL)); '); // ... } public function down(Schema $schema): void { // ... $this->addSql(/** @lang MySQL */' ALTER TABLE Building_address DROP CONSTRAINT CK___Building_address___building_name__xor__address_number; '); // ... } public function isTransactional(): bool { return false; }
3. Execute the migration
php bin/console doctrine:migrations:migrate -n
4. Import data
Note: you can also run the following commands in a cron job so that your data is regularly updated.
4.1 Localities
php bin/console swiss-geo-bundle:import:localities --no-debug
4.2 Streets
php bin/console swiss-geo-bundle:import:streets --no-debug
4.3 Building addresses
php bin/console swiss-geo-bundle:import:building-addresses --no-debug
4.4 Generate/update documents in Meilisearch
php bin/console swiss-geo-bundle:import:meilisearch:documents:generate --no-debug