-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The GV100AD file from Destatis (the German Federal Statistical Office) is part of their municipal directory system, specifically designed to provide structured data on German municipalities. This file is available in a fixed-length ASCII format, which allows for consistent data entry and processing. The GV100AD updates regularly, with monthly and quarterly releases, capturing essential information about municipalities, including geographical data and demographic statistics.
This PHP library is able to parse GV100AD files and make their content easily accessible.
gv100ad-php is available on Packagist, and installation via Composer is the recommended way to install.
Option 1:
Add this line to your composer.json
file:
"openpotato/gv100ad-php": "^0.1.0"
Option 2:
Run Composer directly:
composer require openpotato/gv100ad-php
The following example iterates through a GV100AD file and prints out all municipalities of Rhineland-Palatinate (Rheinhland-Pfalz):
<?php
include_once(__DIR__.'/vendor/autoload.php');
use OpenPotato\GV100AD\GV100ADReader;
use OpenPotato\GV100AD\Municipality;
/**
* Prints all available attributes of a Municipality object.
*
* @param Municipality $municipality
*/
function print_municipality_attributes($municipality)
{
echo $municipality . PHP_EOL;
echo "Name: " . $municipality->name . PHP_EOL;
echo "Regional Code: " . $municipality->regional_code . PHP_EOL;
echo "Association: " . $municipality->association . PHP_EOL;
echo "Type: " . $municipality->type->name . PHP_EOL;
echo "Area: " . $municipality->area . PHP_EOL;
echo "Inhabitants: " . $municipality->inhabitants . PHP_EOL;
echo "Inhabitants Male: " . $municipality->inhabitants_male . PHP_EOL;
echo "Postal Code: " . $municipality->postal_code . PHP_EOL;
echo "Multiple Postal Codes: " . ($municipality->multiple_postal_codes ? 'true' : 'false') . PHP_EOL;
echo "Tax Office District: " . $municipality->tax_office_district . PHP_EOL;
echo "Higher Regional Court District: " . $municipality->higher_regional_court_district . PHP_EOL;
echo "Regional Court District: " . $municipality->regional_court_district . PHP_EOL;
echo "Local Court District: " . $municipality->local_court_district . PHP_EOL;
echo "Employment Agency District: " . $municipality->employment_agency_district . PHP_EOL;
echo "Timestamp: " . $municipality->timestamp->format('Y-m-d') . PHP_EOL;
echo PHP_EOL;
}
// Path to the GV100AD file, please adjust.
$file_path = "GV100AD_31082024.txt";
// Opens the GV100AD file, iterates through all records and prints the attributes only for
// municipalities of Rhineland-Palatinate
$handle = fopen($file_path, 'r');
if ($handle === false) {
die("Failed to open file: " . $file_path);
}
$gv_reader = new GV100ADReader($handle);
foreach ($gv_reader->read() as $record) {
if ($record instanceof Municipality && strpos($record->regional_code, "07") === 0) {
print_municipality_attributes($record);
}
}
fclose($handle);