A Symfony-based client for accessing the MatrikkelAPI from Kartverket (Norwegian Cadastre). This project provides both SOAP API integration and local database import capabilities for Norwegian address and property data.
The easiest way to get started is using Docker:
# 1. Clone and navigate to the project
git clone <repository-url>
cd matrikkel
# 2. Set up your API credentials (see Configuration section below)
cp .env.example .env
# Edit .env with your actual Matrikkel API credentials
# 3. Run the setup script
./docker-setup.sh
# 4. Access the application
# Web interface: http://localhost:8083
# Console commands: docker compose exec app php bin/console list- Docker
- Docker Compose
- PHP 8.3+
- Required PHP extensions:
ext-soap(for SOAP API)ext-sqlite3(for local database)ext-pgsql(for PostgreSQL support)ext-ctypeext-iconvext-zip
- Composer
You need valid Matrikkel API credentials from Kartverket. Configure them in .env:
# Matrikkel API Configuration
MATRIKKELAPI_LOGIN=your_actual_login
MATRIKKELAPI_PASSWORD=your_actual_password
MATRIKKELAPI_ENVIRONMENT=prod # or 'test' for testingMATRIKKELAPI_LOGIN- Your Matrikkel API usernameMATRIKKELAPI_PASSWORD- Your Matrikkel API passwordMATRIKKELAPI_ENVIRONMENT- API environment (prodortest)
# Build and start containers
docker compose up -d
# View logs
docker compose logs -f
# Run console commands
docker compose exec app php bin/console matrikkel:ping# Install dependencies
composer install
# Install PHP SOAP extension (Ubuntu/Debian)
sudo apt-get install php-soap
# Clear cache
php bin/console cache:clear
# Test the connection
php bin/console matrikkel:pingTest API connection:
php bin/console matrikkel:pingImport data:
# Complete import (both phases combined)
php bin/console matrikkel:import --kommune=4627 --organisasjonsnummer=964338442
# With limit for testing
php bin/console matrikkel:import --kommune=4627 --organisasjonsnummer=964338442 --limit=10
# Skip Phase 1 (only import buildings and addresses)
php bin/console matrikkel:import --kommune=4627 --skip-phase1
# Skip Phase 2 (only import properties and owners)
php bin/console matrikkel:import --kommune=4627 --skip-phase2Alternative: Two-phase approach (if needed):
# Phase 1: Import base data (kommune, matrikkelenheter, personer, eierforhold)
php bin/console matrikkel:phase1-import --kommune=4627 --organisasjonsnummer=964338442
# Phase 2: Import building data (veger, bygninger, bruksenheter, adresser)
php bin/console matrikkel:phase2-import --kommune=4627 --organisasjonsnummer=964338442Debug commands:
# Debug matrikkelenhet structure from API
php bin/console matrikkel:debug-matrikkelenhet
# Test NedlastningClient bulk downloads
php bin/console matrikkel:test-nedlastningNote: For searching individual addresses, property units, cadastral units, municipalities, or code lists, use the REST API endpoints below instead of console commands.
The project now includes a comprehensive REST API that provides JSON access to all Matrikkel functionality:
Base URL: http://localhost:8083/api
Available Endpoints:
# API Documentation
GET /api/endpoints # List all available endpoints
GET /api/ping # API health check
# Address Services
GET /api/address/{id} # Get address by ID
GET /api/address/search?q={query} # Search addresses via API
GET /api/address/search/db?q={query} # Search addresses in local DB
GET /api/address/postal/{postnummer} # Get postal area
# Municipality Services
GET /api/municipality/{id} # Get municipality by ID
GET /api/municipality/number/{number} # Get municipality by number
# Property Unit Services
GET /api/property-unit/{id} # Get property unit by ID
GET /api/property-unit/address/{addressId} # Get units for address
# Cadastral Unit Services
GET /api/cadastral-unit/{id} # Get by ID
GET /api/cadastral-unit/{knr}/{gnr}/{bnr} # Get by matrikkel number
GET /api/cadastral-unit/{knr}/{gnr}/{bnr}/{fnr} # With festenummer
GET /api/cadastral-unit/{knr}/{gnr}/{bnr}/{fnr}/{snr} # With section
# Code Lists
GET /api/codelist # Get all code lists
GET /api/codelist/{id} # Get specific code list with codes
# General Search
GET /api/search?q={query}&source=api&limit={number}&offset={start} # Search via Matrikkel API (pagination support)
GET /api/search?q={query}&source=db # Search via local database
### Examples
```bash
# Check API status
curl http://localhost:8083/api/ping
# Search for address
curl "http://localhost:8083/api/address/search?q=Bergen"
# Get municipality info
curl http://localhost:8083/api/municipality/4601
# Search with pagination
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=0" # First 50 results
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=50" # Next 50 results
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=100" # Results 101-150
# Search in local database
curl "http://localhost:8083/api/search?q=Oslo&source=db"
**Example API Usage**:
```bash
# Test API health
curl http://localhost:8083/api/ping
# Search for addresses
curl "http://localhost:8083/api/address/search?q=Bergen"
# Get municipality data
curl http://localhost:8083/api/municipality/4601
# Search with pagination - get results beyond 100
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=0" # First 50 results
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=50" # Next 50 results
curl "http://localhost:8083/api/search?q=oslo&source=api&limit=50&offset=100" # Results 101-150
# Search with local database
curl "http://localhost:8083/api/search?q=Oslo&source=db"
All endpoints return JSON with this structure:
{
"data": { ... },
"timestamp": "2025-10-03T13:57:21+00:00",
"status": "success"
}# Start containers
docker compose up -d
# Stop containers
docker compose down
# View logs
docker compose logs -f
# Run console commands
docker compose exec app php bin/console <command>
# Access container shell
docker compose exec app bash
# Rebuild containers
docker compose build --no-cacheThe project provides a unified import command that handles all data import in two phases:
Phase 1 (Base Data):
- Kommune (municipality)
- Matrikkelenheter (cadastral units/properties)
- Personer (owners - physical and legal persons)
- Eierforhold (ownership relations)
Phase 2 (Building Data):
- Veger (roads/streets)
- Bruksenheter (property units)
- Bygninger (buildings)
- Adresser (addresses)
Basic Usage:
# Full import for a municipality with owner filter
php bin/console matrikkel:import --kommune=4627 --organisasjonsnummer=964338442
# Test with limited data
php bin/console matrikkel:import --kommune=4627 --organisasjonsnummer=964338442 --limit=10
# Import only Phase 1 (base data)
php bin/console matrikkel:import --kommune=4627 --skip-phase2
# Import only Phase 2 (building data)
php bin/console matrikkel:import --kommune=4627 --skip-phase1Available Options:
--kommune=XXXX- Required: 4-digit municipality number--organisasjonsnummer=XXXXXX- Filter by organization number (owner)--limit=N- Limit number of matrikkelenheter to import (for testing)--skip-phase1- Skip Phase 1, only run Phase 2--skip-phase2- Skip Phase 2, only run Phase 1
Example: Full Import for AskΓΈy Kommune:
php bin/console matrikkel:import --kommune=4627 --organisasjonsnummer=964338442This will import:
- 1 kommune
- 693 matrikkelenheter
- 442 personer
- 329 veger
- 879 bruksenheter
- 692 bygninger
- 263 adresser
Performance:
- Phase 1: ~12 seconds (base data)
- Phase 2: ~23 seconds (building data)
- Total: ~35 seconds for complete dataset
The individual phase commands are still available if you need more control:
# Run Phase 1 only
php bin/console matrikkel:phase1-import --kommune=4627 --organisasjonsnummer=964338442
# Run Phase 2 only
php bin/console matrikkel:phase2-import --kommune=4627 --organisasjonsnummer=964338442The project uses PostgreSQL to store imported data. The complete schema includes 7 primary tables:
matrikkel_kommuner- Norwegian municipalitiesmatrikkel_matrikkelenheter- Cadastral units (properties)matrikkel_personer- Property owners (physical and legal persons)matrikkel_eierforhold- Ownership records (junction table)matrikkel_veger- Roads/streetsmatrikkel_bygninger- Buildings with detailed property datamatrikkel_bruksenheter- Property units (apartments, etc.)matrikkel_adresser- Addresses
Visual Schema Diagram:
For the complete database schema, see migrations/V1__baseline_schema.sql.
- Production API: https://prodtest.matrikkel.no/matrikkelapi/wsapi/v1/dokumentasjon/index.html
- Test Environment: Available through Kartverket
- AdresseClient - Address lookup and search
- BruksenhetClient - Property units
- KommuneClient - Municipality data
- KodelisteClient - Code lists and references
- MatrikkelenhetClient - Cadastral units
- MatrikkelsokClient - General cadastre search
SOAP Extension Missing:
# Ubuntu/Debian
sudo apt-get install php-soap
# CentOS/RHEL
sudo yum install php-soapPermission Issues with Docker:
# Fix file permissions
sudo chown -R $USER:$USER ./var
chmod -R 775 ./varAPI Connection Issues:
- Verify your credentials in
.env - Test with:
php bin/console matrikkel:ping - Check if you're using the correct environment (
prodvstest)
Cache Issues:
# Clear Symfony cache
php bin/console cache:clear
# With Docker
docker compose exec app php bin/console cache:clearCoordinate Transformation Notice:
The current implementation includes a basic stub for coordinate transformations (UTM β Lat/Long). For production use requiring precise coordinate transformations, consider implementing a proper coordinate transformation library or service.
src/
βββ Client/ # SOAP client implementations
βββ Console/ # Symfony console commands
βββ Entity/ # Data entities
βββ LocalDb/ # Local database services
βββ Service/ # Business logic services
Extend AbstractCommand class and place in src/Console/ directory.
Services are configured in config/services.yaml using the factory pattern for SOAP clients.
GPL-3.0-or-later β see the full text in LICENSE.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For more information about the Norwegian Cadastre system, visit Kartverket.