Skip to content

Switch geometry import format from GeoJSON to WKT - #37

Merged
LdDl merged 1 commit into
masterfrom
wkt
Dec 23, 2025
Merged

LdDl merged 1 commit into
masterfrom
wkt

Conversation

@LdDl

@LdDl LdDl commented Dec 23, 2025 •

Copy link
Copy Markdown
Owner
  • Switch CSV geometry parsing from GeoJSON to WKT format
  • WKT is the default output format of osm2ch, simplifying setup

**BREAKING CHANGE:
Existing CSV files with GeoJSON geometry will no longer work.

  • To make it work it is recommended to reconvert is via osm2ch
  • or here is snippet in python if you don't want to run osm2ch again:
# convert_to_wkt.py
import json, sys, re

def convert(match):
    g = json.loads(match.group().replace('""', '"').strip('"'))
    if g['type'] == 'Point':
        return f"POINT({g['coordinates'][0]} {g['coordinates'][1]})"
    else:  # LineString
        coords = ', '.join(f"{c[0]} {c[1]}" for c in g['coordinates'])
        return f"LINESTRING({coords})"

for filename in sys.argv[1:]:
    with open(filename) as f:
        content = f.read()
    result = re.sub(r'"?\{""type""[^}]+\}"?', convert, content)
    with open(filename, 'w') as f:
        f.write(result)
    print(f"Converted: {filename}")
python convert_to_wkt.py map.csv map_vertices.csv

@LdDl LdDl self-assigned this Dec 23, 2025
@LdDl LdDl added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 23, 2025
@LdDl
LdDl merged commit 5d646f1 into master Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址