-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and new raw files parser #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
from pathlib import Path | ||
|
||
import logging | ||
import os | ||
|
||
class RAWParser: | ||
result: dict | None | ||
|
||
def __init__(self, file: Path): | ||
self.result = None | ||
self.file = file | ||
|
||
def parse(self): | ||
result = {} | ||
self.parse_recursively(self.file, result) | ||
self.result = result | ||
#logging.debug(result) | ||
return self.result | ||
|
||
def parse_recursively(self, root, result): | ||
for dirname in os.listdir(root): | ||
#logging.debug(f"1: {root / dirname}") | ||
if os.path.isfile(root / dirname): | ||
filepath = root / dirname | ||
with (root / dirname).open( | ||
encoding="iso-8859-1", | ||
) as f: | ||
result[Path(*filepath.parts[1:]).as_posix()] = f.read() | ||
elif os.path.isdir(root / dirname): | ||
#logging.debug(f"2: {dirname}") | ||
self.parse_recursively(root / dirname, result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the use case for this? Why is a single file und thus raw string per data item not enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, in FIR Langen they used an own script, to paste some data into maps. It worked simply by finding .import and replacing it with txt files in the path. I know mapbuilder can import plain txt files, but I would need to get every single of these 100 txt files into mapbuilder.toml. I found it would be simpler if I could make the mapbuilder to search for the needed txt files by itself by parsing the whole directory with all these txt files and then in jinja provide a path to the file inside given directory. I couldn't just paste the data into maps, because I it was actually reused in completely separate maps for separate profiles. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from pathlib import Path | ||
|
||
import re | ||
import logging | ||
import numpy as np | ||
import shapely | ||
import shapely.ops | ||
|
@@ -81,7 +83,6 @@ def concat(base: dict, keys: list[str]) -> list: | |
|
||
return result | ||
|
||
|
||
def to_text_buffer(geometry, label: str, color: str, adapt_to_length=True): | ||
point = geometry[0] if isinstance(geometry, list) else geometry | ||
|
||
|
@@ -97,6 +98,9 @@ def to_text_buffer(geometry, label: str, color: str, adapt_to_length=True): | |
|
||
_render_polygon(lines, [buffer], color) | ||
|
||
for i in range(len(lines)): | ||
lines[i] = lines[i].replace("COLOR", "\nCOLOR") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like the wrong position to fix this. Are you sure you are using the Jinja templating language correctly? |
||
|
||
return "\n".join(lines) | ||
|
||
|
||
|
@@ -107,7 +111,7 @@ def to_text(geometry, label: str): | |
return "" | ||
|
||
labeltext, _, _ = label.partition("#") | ||
return f"TEXT:{coord2es(point.coords[0])}:{labeltext}" | ||
return f"TEXT:{coord2es(point.coords[0])}:{labeltext}\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Newlines should be handled by Jinja templates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will try to replicate the issues with newlines one more time and will send a result. |
||
|
||
|
||
def to_symbol(geometry, symbol): | ||
|
@@ -173,20 +177,20 @@ def envelope(geometries): | |
def to_poly(geometries, designator: str, color: str, coordpoly=False): | ||
lines = [f"// {designator}"] if designator else [] | ||
|
||
_render_polygon(lines, _get_geoms(geometries), color) | ||
|
||
if coordpoly: | ||
lines.extend((f"COORDPOLY:{coordpoly}", "")) | ||
_render_polygon(lines, _get_geoms(geometries), color, coordpoly) | ||
|
||
return "\n".join(lines) | ||
|
||
|
||
def _render_polygon(lines, polygons, color): | ||
def _render_polygon(lines, polygons, color, coordpoly=False): | ||
for polygon in polygons: | ||
lines.append(f"COLOR:{color}") | ||
|
||
for point in polygon.coords: | ||
lines.append(f"COORD:{coord2es((point[0], point[1]))}") | ||
|
||
if coordpoly: | ||
lines.extend((f"COORDPOLY:{coordpoly}", "")) | ||
|
||
|
||
def _render_coords(lines, linestring): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either remove debugging statements or leave them in if they provide any benefit.