Download the PHP package plin-code/laravel-istat-geography without Composer

On this page you can find all versions of the php package plin-code/laravel-istat-geography. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-istat-geography

Laravel ISTAT Geography

Packagist PHP from Packagist Laravel versions GitHub Workflow Status (main) Total Downloads

Laravel ISTAT Geography

A Laravel package for importing and managing Italian geographical data from ISTAT.

Features

Requirements

Installation

Quick Start

  1. Install the package:

  2. Publish the configuration:

  3. Run migrations:

  4. Import the data:

That's it! You now have all Italian geographical data in your database.

Commands

geography:import

Performs a full import of all geographical data from ISTAT. Use this for the initial data load.

Options

Option Description
--cap Also import postal codes (CAP) after ISTAT data
--cap-only Import only postal codes, skip ISTAT data (requires existing municipalities)
--cap-file=<path> Use a local JSON file for CAP data instead of downloading
--coordinates Also import municipality coordinates (latitude and longitude) after ISTAT data
--coordinates-only Import only coordinates, skip ISTAT data (requires existing municipalities)
--coordinates-file=<path> Use a local JSON file (plain or gzipped) for coordinates instead of downloading

Examples

Note: The remote GeoJSON with geometries is ~464MB. Using --cap-file with a preprocessed JSON file (~3MB) is recommended for better performance.

geography:download-cap

Downloads CAP GeoJSON data and saves it locally for offline import. Useful when you want to download once and import multiple times.

After downloading, import with:

geography:download-coordinates

Downloads the coordinates dataset and saves it locally (decompressed) for offline import.

After downloading, import with:

geography:update

Incrementally synchronizes your database with the latest ISTAT data. It compares the current ISTAT CSV against your existing records and applies only the differences: new records are added, changed records are updated, and records no longer present in ISTAT are soft-deleted.

Options

Option Description
--dry-run Simulate the update without making any database changes. Shows what would be added, modified, or deleted.
--force Continue execution even if non-critical errors occur (errors are logged as warnings).

Verbosity Levels

Flag Output
(none) Final summary only (e.g. 3 added, 1 modified, 0 deleted)
-v Download progress, list of new/modified/suppressed records, progress bar
-vv Field-level change details (e.g. name: Old Name โ†’ New Name)
-vvv Debug output with timing information for each operation

Examples

All database operations are wrapped in a transaction. If any error occurs (and --force is not set), all changes are automatically rolled back.

Configuration

Publish the configuration file:

The config/istat-geography.php file allows you to customize:

Database Connection

By default the package uses your application's default database connection. To store the geographical tables on a separate connection, set the connection key in config/istat-geography.php or the ISTAT_DB_CONNECTION environment variable:

[!NOTE] The connection config key is additive and fully backward compatible. If you published the config file before this option existed, the package falls back to your default database connection (config('database.default')), so no action is required on upgrade. To opt into a custom connection, either republish the config file or set the ISTAT_DB_CONNECTION environment variable.

Table Names

The tables key controls the table names used by both the migrations and the models. Set it before running the migrations for the first time: the migrations create the tables (and their foreign keys) with the configured names, and the models read and write the same tables.

Changing the names after the tables already exist does not rename them. In that case rename the tables yourself with a migration, then update the config. A custom model that defines its own $table property keeps using that table.

Municipality Coordinates

Coordinates are optional. The extend_municipalities_with_coordinates migration adds two nullable columns, latitude and longitude, to the municipalities table, and they stay empty until you import them.

Import them once with --coordinates, or enable the import on every geography:import run:

Each municipality gets one representative point of its administrative area: the centroid of the municipal boundary when it falls inside the municipality, otherwise a point guaranteed to be inside it. The point is not the town hall or the main inhabited centre, so for large or irregular municipalities it can be a few kilometres away from the town centre (and sometimes in open countryside). It is meant for maps, sorting by distance and proximity searches, not for navigation.

geography:update never overwrites coordinates, because they are not ISTAT fields. When ISTAT adds a new municipality, it gets coordinates the next time you run the coordinates import with an updated dataset.

Example Configuration

Models

The package provides three Eloquent models:

Region

Province

Municipality

ISTAT Fields

Each model exposes a static istatFields() method that returns the list of fields managed by ISTAT data. These are the fields that the geography:update command is allowed to overwrite. Any additional fields you add to your extended models will not be touched during updates.

Extending Models

If you want to use the package models in your main project, you can extend them:

Remember to update the models section in the configuration file to point to your custom classes. The import and update services and the model relationships (for example $region->provinces or $municipality->province) then use your classes.

Database Structure

Regions

Provinces

Municipalities

Relationships

Replacing Existing Command

If you already have a geography:import command in your project, you can replace it with the package's command:

AI guidelines (Laravel Boost)

This package ships AI guidelines for Laravel Boost at resources/boost/guidelines/core.blade.php, the path the Boost documentation gives package authors. It is a short, always in context brief on the three models, their tables, columns and relations, the geography:* commands and the config keys, so an agent uses the package models instead of creating its own regions, provinces or municipalities tables.

Install Boost 2.5 or higher with composer require laravel/boost --dev then php artisan boost:install, selecting this package when Boost asks which third party guidelines to install. On an app that already has Boost installed, php artisan boost:update --discover offers the newly detected package.

Testing

Run the test suite:

The package includes:

Test Coverage

Data Sources

ISTAT Data

Geographic data (regions, provinces, municipalities) is sourced from ISTAT (Italian National Institute of Statistics), the official Italian government statistics agency.

Postal Codes (CAP) and Boundaries

Postal code data (data-properties-v1) and the full boundaries GeoJSON (data-geo-v1) are sourced from Zornade Data Downloads. They are derived from OpenStreetMap addresses, so they are licensed under the Open Database License (ODbL). If you use or redistribute them, keep this attribution and share derived databases under the same license:

ยฉ OpenStreetMap contributors (ODbL). Data processed by Zornade (https://zornade.com).

Municipality Coordinates

Coordinates are derived from the ISTAT municipal boundaries (Confini Amministrativi) published by Zornade Data Downloads, licensed under CC BY 4.0. If you show these coordinates in your product, keep this attribution visible:

Source: ISTAT, administrative boundaries (CC BY 4.0). Data processed by Zornade (https://zornade.com).

The points were computed by this package from the boundary polygons (centroid in EPSG:3035, or a point on surface when the centroid falls outside the polygon), so they are an adaptation of the original data. The dataset file includes the same attribution, license and generation date in its meta section.

A huge thanks to Zornade for their incredible work in making Italian public data freely available. Their dedication to open data helps developers build better applications for Italian users.

Regenerating the Coordinates Dataset

Maintainers can rebuild the dataset with scripts/build-coordinates-dataset.php (PHP with pdo_sqlite, plus Docker for the official GDAL image). It downloads the boundaries and the current ISTAT list, computes one point per municipality and writes build/municipality_coordinates_dataset.json.gz:

Municipalities created by a merger after the boundaries were published are computed on the union of their predecessors, listed in MERGED_MUNICIPALITIES inside the script. The script stops with an error when a municipality has no polygon and no merger entry.

Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-istat-geography with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^12.0 || ^13.0
league/csv Version ^9.24
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package plin-code/laravel-istat-geography contains the following files

Loading the files please wait ...