@nexgen-os/geopunt 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +64 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexgen OS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@nexgen-os/geopunt` — the Flemish address register
|
|
2
|
+
|
|
3
|
+
The Geolocation API of Digitaal Vlaanderen on the Flemish base registers, which also serves the Brussels UrbIS addresses (region `BE-BRU` on those answers). Source `geopunt`. MIT; open, no key. Its matching is loose on house numbers (it answers `Korenmarkt 10` for `Korenmarkt 1`): a place whose number is not the one typed keeps the street only, at precision `street`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { geopunt } from '@nexgen-os/geopunt';
|
|
7
|
+
|
|
8
|
+
const geocoder = geopunt();
|
|
9
|
+
const [place] = await geocoder.search('Korenmarkt 10, 9000 Gent');
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The place is the standard shape of `@nexgen-os/core` (address, WGS 84 point,
|
|
13
|
+
precision, source); `placeFields(place)` gives the place columns of `participants` it fills.
|
|
14
|
+
Decision [0009](../../../docs/decisions/0009-what-applies-follows-the-region.md).
|
|
2
15
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Fetch, Geocoder } from '@nexgen-os/core';
|
|
2
|
+
interface Common {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
fetch?: Fetch;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The Flemish address register. Its matching is loose on house numbers (it
|
|
8
|
+
* answers `Korenmarkt 10` for `Korenmarkt 1`): a place whose number is not
|
|
9
|
+
* one typed in the search keeps the street only, at precision `street`.
|
|
10
|
+
* It does not give the NIS code of the municipality.
|
|
11
|
+
*/
|
|
12
|
+
export declare function geopunt(options?: Common): Geocoder;
|
|
13
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Geopunt — the Flemish address register as a Geocoder of the core's shape.
|
|
2
|
+
// Open, no key.
|
|
3
|
+
/**
|
|
4
|
+
* The Flemish address register. Its matching is loose on house numbers (it
|
|
5
|
+
* answers `Korenmarkt 10` for `Korenmarkt 1`): a place whose number is not
|
|
6
|
+
* one typed in the search keeps the street only, at precision `street`.
|
|
7
|
+
* It does not give the NIS code of the municipality.
|
|
8
|
+
*/
|
|
9
|
+
export function geopunt(options = {}) {
|
|
10
|
+
const base = trimSlash(options.baseUrl ?? 'https://geo.api.vlaanderen.be/geolocation');
|
|
11
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
12
|
+
return {
|
|
13
|
+
source_code: 'geopunt',
|
|
14
|
+
async search(text, search = {}) {
|
|
15
|
+
const params = new URLSearchParams({ q: text, c: String(search.limit ?? 5) });
|
|
16
|
+
const body = (await getJson(doFetch, `${base}/v4/Location?${params}`));
|
|
17
|
+
const typed = new Set(text.toLowerCase().split(/[\s,]+/));
|
|
18
|
+
return body.LocationResult.map((l) => fromGeopunt(l, typed));
|
|
19
|
+
},
|
|
20
|
+
async reverse(lon, lat) {
|
|
21
|
+
const body = (await getJson(doFetch, `${base}/v4/Location?latlon=${lat},${lon}&c=1`));
|
|
22
|
+
return body.LocationResult[0] ? fromGeopunt(body.LocationResult[0]) : null;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function fromGeopunt(l, typed) {
|
|
27
|
+
const type = l.LocationType;
|
|
28
|
+
// A house number the search did not ask for is the register's guess, not the place.
|
|
29
|
+
const numberAsked = !l.Housenumber || !typed || typed.has(l.Housenumber.toLowerCase());
|
|
30
|
+
let precision = type.includes('gemeente')
|
|
31
|
+
? 'city'
|
|
32
|
+
: type.endsWith('straat') || type.includes('geïnterpoleerd')
|
|
33
|
+
? 'street'
|
|
34
|
+
: type === 'perceel'
|
|
35
|
+
? 'parcel'
|
|
36
|
+
: l.Housenumber
|
|
37
|
+
? 'rooftop'
|
|
38
|
+
: 'city';
|
|
39
|
+
if (!numberAsked && precision === 'rooftop')
|
|
40
|
+
precision = 'street';
|
|
41
|
+
const street = [l.Thoroughfarename, numberAsked ? l.Housenumber : null].filter(Boolean).join(' ') || null;
|
|
42
|
+
const region = type.startsWith('urbis') ? 'BE-BRU' : 'BE-VLG';
|
|
43
|
+
const place = {
|
|
44
|
+
address: { address_line1: street, address_line2: null, postal_code: l.Zipcode, city: l.Municipality, region, municipality_code: null, country: 'BE' },
|
|
45
|
+
lon: l.Location.Lon_WGS84,
|
|
46
|
+
lat: l.Location.Lat_WGS84,
|
|
47
|
+
precision,
|
|
48
|
+
source_code: 'geopunt',
|
|
49
|
+
label: numberAsked ? l.FormattedAddress : [street, [l.Zipcode, l.Municipality].filter(Boolean).join(' ')].filter(Boolean).join(', '),
|
|
50
|
+
};
|
|
51
|
+
// The ID of a Flemish house number is its identifier in the address register.
|
|
52
|
+
if (region === 'BE-VLG' && precision === 'rooftop' && l.ID !== null)
|
|
53
|
+
place.identifier = { scheme: 'vlaanderen_address', value: String(l.ID) };
|
|
54
|
+
return place;
|
|
55
|
+
}
|
|
56
|
+
async function getJson(doFetch, url) {
|
|
57
|
+
const response = await doFetch(url, { headers: { Accept: 'application/json' } });
|
|
58
|
+
if (!response.ok)
|
|
59
|
+
throw new Error(`geocoder_unavailable: ${response.status} from ${url}`);
|
|
60
|
+
return response.json();
|
|
61
|
+
}
|
|
62
|
+
function trimSlash(url) {
|
|
63
|
+
return url.replace(/\/+$/, '');
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexgen-os/geopunt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "The Flemish address register (Geopunt) as a Nexgen OS geocoder.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nexgen-os/nexgen-os.git",
|
|
9
|
+
"directory": "packages/connectors/geopunt"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.build.json"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nexgen-os/core": "^0.4.0"
|
|
36
|
+
}
|
|
37
|
+
}
|