Skip to content

Commit 9a461cf

Browse files
authored
Merge pull request #9 from norwegian-geotechnical-institute/fix/crash_if_misssing_coordinate_system
Fix crash if trying to write a kof file with unknown coordinate system
2 parents d93d4f8 + 0d08745 commit 9a461cf

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

.github/workflows/branch.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
fail-fast: false
88
matrix:
99
python-version: ['3.9']
10-
poetry-version: ['1.2.1']
10+
poetry-version: ['1.2.2']
1111
os: [ubuntu-latest]
1212
runs-on: ${{ matrix.os }}
1313
steps:
@@ -30,7 +30,7 @@ jobs:
3030
fail-fast: false
3131
matrix:
3232
python-version: ['3.9']
33-
poetry-version: ['1.2.1']
33+
poetry-version: ['1.2.2']
3434
os: [ubuntu-latest]
3535
runs-on: ${{ matrix.os }}
3636
steps:

CHANGES.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# NGI Python KOF Parser Package
1+
# Python KOF Parser Package
2+
3+
## Version 0.0.12
4+
_2022-11-02_
5+
6+
Add
7+
8+
- Add missing srid/epsg 3857 and SOSI code 300 for WGS84 Web Mercator / Pseudo-Mercator.
9+
10+
Fix
11+
12+
- Crash in KOF writer if target srid/epsg has no SOSI definition.
213

314
## Version 0.0.11
415
_2022-10-21_

poetry.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude = '''
1515

1616
[tool.poetry]
1717
name = "kof-parser"
18-
version = "0.0.11"
18+
version = "0.0.12"
1919
description = "A KOF file parser. Follows Norkart's KOF 2.0 specification from 2005."
2020
license = "MIT"
2121
authors = ["Magnus Mariero <[email protected]>", "Jostein Leira <[email protected]>"]

src/kof_parser/KoordSys.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ UTM sone 35 basert på ED50; EPSG 23035;35;23035
5050
UTM sone 35 basert på EUREF89;Ref INSPIRE Req 7 (ETRS89-TM35)) EPSG 25835;25;25835
5151
UTM sone 36 basert på ED50; EPSG 23036;36;23036
5252
UTM sone 36 basert på EUREF89;Ref INSPIRE Req 7 (ETRS89-TM36)) EPSG 25836;26;25836
53+
Web Mercator / Pseudo-Mercator;Spherical Mercator. Mye brukt projeksjon for webkart, blant annet for Google-maps, OpenStreetMap, Bing, ArcGIS, ESRI. Tidligere bruk benyttet en EPSG:900913.;300;3857
5354
WGS84 Geografisk 2d;WGS84 Geografisk 2d, ingen projeksjon, EPSG 4326;184;4326
5455
WGS84 UTM 29 2d;UTM Sone 29 basert på WGS84,2d (horisontal), EPSG 32629;59;32629
5556
WGS84 UTM 30 2d;UTM Sone 30 basert på WGS84,2d (horisontal), EPSG 32630;60;32630

src/kof_parser/kof.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def __init__(self):
2828
self.code_to_srid_mapping = _code_to_srid_mapping
2929

3030
def get_srid(self, code: int) -> Optional[int]:
31+
"""
32+
Get srid/epsg from SOSI code
33+
"""
3134
return self.code_to_srid_mapping.get(code)
3235

3336
def get_code(self, srid: int) -> Optional[int]:
37+
"""
38+
Get SOSI code from srid/epsg
39+
"""
3440
return self.srid_to_code_mapping.get(srid)

src/kof_parser/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create_admin_block(self, project_name: str, srid: int, swap_easting_northing
3939
"""
4040
date = datetime.utcnow().strftime("%d%m%Y")
4141
version = "1"
42-
code = self.get_code(srid=srid)
42+
sosi_code = self.get_code(srid=srid) or ""
4343
municipality = ""
4444
if swap_easting_northing:
4545
units = "$21100000000"
@@ -50,7 +50,7 @@ def create_admin_block(self, project_name: str, srid: int, swap_easting_northing
5050
# "-01 OOOOOOOOOOOO DDMMYYYY VVV KKKKKKK KKKK $RVAllllllll OOOOOOOOOOOO"
5151
admin_block = " 00 Oppdrag Dato Ver K.sys Komm $21100000000 Observer \n"
5252
admin_block += (
53-
f" 01 {project_name[:12]:<12} {date[:8]:>8} {version[:3]:>3} {code:>7} "
53+
f" 01 {project_name[:12]:<12} {date[:8]:>8} {version[:3]:>3} {sosi_code:>7} "
5454
f"{municipality:>4} {units[:12]:<12} {observer[:12]:<12}\n"
5555
)
5656
return admin_block

0 commit comments

Comments
 (0)