Arbeidstilsynet.Common.GeoNorge
4.1.1
Prefix Reserved
See the version list below for details.
dotnet add package Arbeidstilsynet.Common.GeoNorge --version 4.1.1
NuGet\Install-Package Arbeidstilsynet.Common.GeoNorge -Version 4.1.1
<PackageReference Include="Arbeidstilsynet.Common.GeoNorge" Version="4.1.1" />
<PackageVersion Include="Arbeidstilsynet.Common.GeoNorge" Version="4.1.1" />
<PackageReference Include="Arbeidstilsynet.Common.GeoNorge" />
paket add Arbeidstilsynet.Common.GeoNorge --version 4.1.1
#r "nuget: Arbeidstilsynet.Common.GeoNorge, 4.1.1"
#:package Arbeidstilsynet.Common.GeoNorge@4.1.1
#addin nuget:?package=Arbeidstilsynet.Common.GeoNorge&version=4.1.1
#tool nuget:?package=Arbeidstilsynet.Common.GeoNorge&version=4.1.1
Arbeidstilsynet.Common.GeoNorge
An abstraction over the GeoNorge APIs Adresser, Kommuneinfo and Kartverket's Eiendom. It ships:
- The high-level ports
IAddressSearch,IFylkeKommuneApiandIPropertySearch(plusAddressSearchExtensions) that cover the most common use cases and return the Kiota-generated models directly. - The Kiota-generated
AdresserClient,KommuneInfoClientandEiendomClient(generated from the official OpenAPI specifications) for local adaptation.EiendomClientincludes only cadastral-number geocoding (GET /geokoding), not nearby-property searches.
Use the ports if you need to:
- find the closest address to a given coordinate
- find the location of a specific address
- find cadastral parcels and their locations, even when a property has no registered addresses
- get information about Norwegian counties (fylker) and municipalities (kommuner)
📖 Installation
dotnet add package Arbeidstilsynet.Common.GeoNorge
🧑💻 Registering the services
Add to your service collection:
using Arbeidstilsynet.Common.GeoNorge.DependencyInjection;
builder.Services.AddGeoNorge();
This registers the ports (IAddressSearch, IFylkeKommuneApi, IPropertySearch) as well as the generated clients (AdresserClient, KommuneInfoClient, EiendomClient).
By default Adresser and Kommuneinfo target https://ws.geonorge.no/ (under /adresser/v1 and /kommuneinfo/v1). Eiendom independently targets https://api.kartverket.no/eiendom/v1 and requires no authentication. BaseUrl controls only the first two clients; PropertyBaseUrl controls Eiendom. Both settings take a host/base URL, with the API-specific path appended automatically. You can override them and opt into approximate Svalbard/Jan Mayen data:
builder.Services.AddGeoNorge(
new GeoNorgeConfig
{
BaseUrl = "https://ws.geonorge.no/",
PropertyBaseUrl = "https://api.kartverket.no/",
// Svalbard and Jan Mayen are not part of the GeoNorge dataset.
// When enabled, IFylkeKommuneApi is decorated to supplement responses
// with synthetic entries for Svalbard (fylke 21, kommune 2100) and
// Jan Mayen (fylke 22, kommune 2211).
UseApproximateSvalbardAndJanMayen = true,
}
);
If you need to customize the retry/timeouts/circuit-breaker behavior, use the resilience callback (applied to all three clients):
builder.Services.AddGeoNorge(
new GeoNorgeConfig { BaseUrl = "https://ws.geonorge.no/" },
options =>
{
options.Retry.MaxRetryAttempts = 2;
options.AttemptTimeout.Timeout = TimeSpan.FromSeconds(15);
options.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(1);
}
);
Usage
Address Search Examples
using Arbeidstilsynet.Common.GeoNorge.Adresser.Punktsok;
using Arbeidstilsynet.Common.GeoNorge.Adresser.Sok;
public class AddressService
{
private readonly IAddressSearch _addressSearch;
// Inject the IAddressSearch interface into your service
public AddressService(IAddressSearch addressSearch)
{
_addressSearch = addressSearch;
}
public async Task Examples()
{
// Find the closest address to a given coordinate:
var address = await _addressSearch.GetClosestAddress(
new PunktsokRequestBuilder.PunktsokRequestBuilderGetQueryParameters
{
Lat = 59.9139f,
Lon = 10.7522f,
Radius = 1000,
}
);
// If you want to find all addresses within a certain radius of a point:
var paginatedResult = await _addressSearch.SearchAddressesByPoint(
new PunktsokRequestBuilder.PunktsokRequestBuilderGetQueryParameters
{
Lat = 59.9139f,
Lon = 10.7522f,
Radius = 1000,
}
);
// Search for addresses by a text query:
var searchResult = await _addressSearch.SearchAddresses(
new SokRequestBuilder.SokRequestBuilderGetQueryParameters
{
Sok = "Karl Johans gate 1, Oslo",
}
);
// If you only want the first result, you can use the QuickSearchLocation extension method:
var location = await _addressSearch.QuickSearchLocation(
new SokRequestBuilder.SokRequestBuilderGetQueryParameters
{
Sok = "Karl Johans gate 1, Oslo",
}
);
}
}
Cadastral Property Search
IPropertySearch is separate from IAddressSearch: it locates cadastral parcels, does not fabricate an address, and does not automatically fall back from address search.
using Arbeidstilsynet.Common.GeoNorge.Eiendom.Geokoding;
using Arbeidstilsynet.Common.GeoNorge.Eiendom.Models;
using Arbeidstilsynet.Common.GeoNorge.Ports;
public class PropertyLocationService(IPropertySearch propertySearch)
{
public Task<GeoKodingRespons?> FindParcels() =>
propertySearch.SearchProperties(
new GeokodingRequestBuilder.GeokodingRequestBuilderGetQueryParameters
{
Kommunenummer = "5512",
Gardsnummer = 2,
Bruksnummer = 16,
}
);
}
Municipality numbers are four-character strings, including leading zeros (for example "0301"). Optional Festenummer and Seksjonsnummer identify leaseholds/sections. Alternatively, set Matrikkelnummer, for example "0301-223/60/0/3", instead of the individual identifier fields.
The port defaults Utkoordsys to EPSG:4326 (WGS84) when omitted; explicit values such as 4258 or 25833 are preserved. Generated clients used directly retain the upstream default of 4258 when the query omits the coordinate system. In WGS84, GeoJSON Point coordinates are [longitude, latitude], not latitude first.
A successful response is a generated GeoKodingRespons with all matching Features. An empty Features collection means no matches. Network (HttpRequestException) and API (ApiException) failures are logged as warnings and return null, not an empty collection; unexpected exceptions propagate. Consumers should handle failure separately from a successful no-match response.
Each feature exposes typed cadastral Properties, including the generated Hovedområde main-parcel flag, and Geometry.Type / Geometry.Coordinates. The official OpenAPI leaves coordinate array items unspecified, so Kiota represents Coordinates as UntypedNode (arrays as UntypedArray with nested nodes). Inspect the geometry type before reading coordinates; do not assume every geometry is a point. Setting Omrade = true requests area geometries instead of representative points and retains their nested GeoJSON coordinates. An explicitly requested nonstandard coordinate system may include Crs in the response.
A property may have several parcels. For example, the addressless property 5512/2/16 returned two representative points on 2026-10-05: [16.82662, 68.68422] (main parcel) and [16.82759, 68.68239] (other parcel). The library neither selects the first/main parcel nor treats a representative point as the exact incident location. Parcel selection, address-empty fallback policy and map/location confirmation belong in consumers.
Kartverket's cadastral data normally lags Matrikkelen by one day; cadastral maps can be incomplete or imprecise. Area geometries do not include boundary-quality information. This API cannot guarantee a precise incident location.
County and Municipality Examples
using Arbeidstilsynet.Common.GeoNorge.KommuneInfo.Punkt;
public class LocationService
{
private readonly IFylkeKommuneApi _fylkeKommuneApi;
// Inject the IFylkeKommuneApi interface into your service
public LocationService(IFylkeKommuneApi fylkeKommuneApi)
{
_fylkeKommuneApi = fylkeKommuneApi;
}
public async Task Examples()
{
// Get all Norwegian counties (fylker):
var fylker = await _fylkeKommuneApi.GetFylker();
// Get all Norwegian municipalities (kommuner):
var kommuner = await _fylkeKommuneApi.GetKommuner();
// Get detailed information about all counties:
var fylkerFullInfo = await _fylkeKommuneApi.GetFylkerFullInfo();
// Get a specific county by number:
var oslo = await _fylkeKommuneApi.GetFylkeByNumber("03");
// Get detailed information about a specific municipality:
var osloKommune = await _fylkeKommuneApi.GetKommuneByNumber("0301");
// Find which municipality contains a specific point:
var kommune = await _fylkeKommuneApi.GetKommuneByPoint(
new PunktRequestBuilder.PunktRequestBuilderGetQueryParameters
{
Nord = 59.9139,
Ost = 10.7522,
Koordsys = 4326,
}
);
}
}
Advanced: using the generated clients directly
AddGeoNorge(...) also exposes the Kiota-generated AdresserClient, KommuneInfoClient and EiendomClient. Use them when you need fields or request configuration that the ports do not surface. Eiendom is restricted to /geokoding. It is recommended that you wrap them in your own narrow interface that matches the intended use in that service or bounded context. That keeps tests simpler, avoids coupling every consumer to the full GeoNorge API surface, and gives you a stable seam if the generated fluent API changes later.
using Arbeidstilsynet.Common.GeoNorge.Adresser;
public interface IAddressLookup
{
Task<OutputGeoPoint?> GetClosestAddress(
double latitude,
double longitude,
int radiusInMeters,
CancellationToken cancellationToken
);
}
public sealed class GeoNorgeAddressLookup(AdresserClient adresserClient) : IAddressLookup
{
public async Task<OutputGeoPoint?> GetClosestAddress(
double latitude,
double longitude,
int radiusInMeters,
CancellationToken cancellationToken
)
{
var result = await adresserClient.Punktsok.GetAsync(
config =>
{
config.QueryParameters.Lat = (float)latitude;
config.QueryParameters.Lon = (float)longitude;
config.QueryParameters.Radius = radiusInMeters;
},
cancellationToken
);
return result?.Adresser?.FirstOrDefault();
}
}
Register the adapter alongside the clients:
builder.Services.AddGeoNorge();
builder.Services.AddScoped<IAddressLookup, GeoNorgeAddressLookup>();
Regenerating the property client
The checked-in openapi-eiendom.json is a snapshot of the official specification referenced by Swagger. Refresh it deliberately, then regenerate from the GeoNorge directory with the repository-pinned tools:
dotnet tool restore
npm run generate:client:eiendom
The script generates only GET /geokoding into Generated\Eiendom, including kiota-lock.json. Do not edit generated files manually. Property tests use deterministic mock HTTP responses; live Kartverket checks are optional and not required by CI.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Http.Resilience (>= 10.10.0)
- Microsoft.Kiota.Bundle (>= 2.1.2)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Http.Resilience (>= 10.10.0)
- Microsoft.Kiota.Bundle (>= 2.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0-alpha2 | 39 | 10/16/2026 |
| 5.0.0-alpha1 | 38 | 10/16/2026 |
| 4.1.1 | 70 | 10/15/2026 |
| 4.1.0 | 809 | 10/7/2026 |
| 4.1.0-alpha | 77 | 10/6/2026 |
| 4.0.1 | 186 | 10/5/2026 |
| 4.0.0 | 2,496 | 7/3/2026 |
| 4.0.0-alpha2 | 126 | 7/2/2026 |
| 4.0.0-alpha1 | 116 | 7/1/2026 |
| 3.1.1 | 1,285 | 7/1/2026 |
| 3.1.0 | 1,305 | 6/4/2026 |
| 3.1.0-alpha1 | 162 | 5/20/2026 |
| 3.0.0 | 1,412 | 4/27/2026 |
| 2.2.1 | 126 | 4/27/2026 |
| 2.2.1-alpha2 | 174 | 4/16/2026 |
| 2.2.1-alpha | 123 | 4/16/2026 |
| 2.2.0 | 135 | 3/6/2026 |
| 2.1.1 | 134 | 2/18/2026 |
| 2.1.1-beta1 | 126 | 2/18/2026 |
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added <!-- for new features. -->
### Changed <!-- for changes in existing functionality. -->
### Deprecated <!-- for soon-to-be removed features. -->
### Removed <!-- for now removed features. -->
### Fixed <!-- for any bug fixes. -->
### Security <!-- in case of vulnerabilities. -->
## 4.1.1
### Fixed
- Standardized NuGet metadata with Arbeidstilsynet as author, an MIT license expression, an embedded icon and Git repository details.
## 4.1.0
### Added
- Added `IPropertySearch` and the Kiota-generated `EiendomClient` for cadastral property-location searches through Kartverket's `/geokoding` endpoint, including properties without registered addresses.
- Property searches preserve all matching parcels and their GeoJSON geometries, default output coordinates to EPSG:4326, and support optional area geometries.
- Added independent `GeoNorgeConfig.PropertyBaseUrl` configuration and dependency injection registration with anonymous authentication and standard HTTP resilience.
## 4.0.1
### Changed
- changed(deps): Applied minor and patch updates to dependencies
## 4.0.0
### Changed
- **BREAKING**: Replaced the hand-written GeoNorge HTTP client implementations with [Kiota](https://learn.microsoft.com/openapi/kiota/)-generated clients (`AdresserClient` and `KommuneInfoClient`), generated from the official OpenAPI specifications. The `IAddressSearch` and `IFylkeKommuneApi` ports and their extensions now accept and expose the generated models directly instead of the package's own domain models. The generated `AdresserClient` and `KommuneInfoClient` are also registered by `AddGeoNorge` (following the Saksarkiv pattern) so consumers can adapt the raw GeoNorge API surface locally.
- The `UseApproximateSvalbardAndJanMayen` option is preserved and now supplements the generated models with synthetic entries for Svalbard and Jan Mayen.
- `IAddressSearch` defaults the coordinate system to EPSG:4326 (WGS84) when it is not specified on the query parameters, instead of the GeoNorge API default of EPSG:4258. Callers can still override this by setting the values explicitly.
### Removed
- **BREAKING**: Removed the hand-written GeoNorge domain models (both response and request models) and the unused `UriExtensions` helper. Consumers should use the generated Kiota models and query parameter types exposed through the ports and extensions.
## 3.1.1
### Changed
- changed(deps): Applied minor and patch updates to dependencies
## 3.1.0
### Added
- Added `UseApproximateSvalbardAndJanMayen` option to `GeoNorgeConfig`. When enabled, registers a
decorator around `IFylkeKommuneApi` that supplements GeoNorge data with synthetic entries for
Svalbard (fylke `21`, kommune `2100`) and Jan Mayen (fylke `22`, kommune `2211`), which are not
included in the GeoNorge API.
- `GetFylker` and `GetKommuner` append the synthetic entries if not already present.
- `GetFylkerFullInfo` appends full info entries for both territories.
- `GetFylkeByNumber` and `GetKommuneByNumber` return synthetic data for the known numbers without
hitting the GeoNorge API.
- `GetKommuneByPoint` short-circuits for WGS84/ETRS89 coordinates falling within approximate
bounding boxes for Svalbard (including Bjørnøya and Hopen) and Jan Mayen.
## 3.0.0
### Removed
- **BREAKING**: Removed dependency on `Arbeidstilsynet.Common.AspNetCore.Extensions`
## 2.2.2
### Added
- feat(search): Added missing query parameters `gardsbruksnummer` and `bruksnummer` to `TextSearchQuery`
- chore: add dotnet8 as targetframework to make it backwards compatible
## 2.2.1
### Changed
- changed(deps): Applied minor and patch updates to dependencies
## 2.2.0
### Changed
- changed(deps): Applied minor and patch updates to dependencies
## 2.1.1
### Changed
- chore: moved package to nuget.org
## 2.1.0
### Changed
- changed(deps): Applied minor and patch updates to dependencies
## 2.0.1
### Changed
- changed(deps): Updated internal package referances (remove prerelease version)
## 2.0.0
### Changed
- changed(deps): Major dotnet updated (v10)
## 1.1.0
### Changed
- fix(deps): use correct version range to only support Microsoft version 8.* packages
## 1.0.1
### Changed
- chore(renovate): all non major update
## 1.0.0
### Added
- Added support for parts of the [kommuneinfo API](https://ws.geonorge.no/kommuneinfo/v1/)
- `/fylker`
- `/fylker/{fylkesnummer}`
- `/kommuner`
- `/kommuner/{kommunenummer}`
- `/punkt` - for getting a kommune and fylke at a specific coordinate
- `/fylkerkommuner` - for details on all fylker (and kommuner) in Norway
## 0.0.2
### Fixed
- Replaced a query parameter handling with the implementation from AspNetCore.Extensions
## 0.0.1
### Added
- Added implementation of the [GeoNorge API](https://ws.geonorge.no/adresser/v1).
- `/sok` with pagination
- `/punktsok` with pagination
- Added extension methods for common access patterns
- `GetClosestAddress` for getting the closest address returned from `/punktsok`
- `QuickSearchLocation` for getting the first hit returned from `/sok`