Support import of various fixed-width formats.

This supports reading: SPSv1, SPSv2.1, P190 and custom
fixed-width formats. Supports skipping lines by startswith()
matching or by complete match (e.g., "EOF").

Closes #300 (SPS v1)
Closes #301 (SPS v2.1)
Closes #302 (P1/90)
This commit is contained in:
D. Berge
2024-04-30 19:05:54 +02:00
parent 934b921f69
commit be0d7b269f
3 changed files with 131 additions and 73 deletions

View File

@@ -1,15 +1,33 @@
import legacy_fwr
import fwr
"""
Preplot importing functions.
"""
def from_file (file, realpath = None):
"""
Return a list of dicts, where each dict has the structure:
{
"line_name": <int>,
"points": [
{
"line_name": <int>,
"point_number": <int>,
"easting": <float>,
"northing": <float>
},
]
}
On error, return a string describing the error condition.
"""
filepath = realpath or file["path"]
if not "type" in file or file["type"] == "sps":
records = legacy_fwr.from_file(filepath, file["format"] if "format" in file else None )
else:
return "Not an SPS file"
records = fwr.from_file(filepath, file)
if type(records) == str:
# This is an error message
return records
lines = []
line_names = set([r["line_name"] for r in records])