xyc module#
XYC file model.#
dfastio.xyc.models
#
XYC file reader and writer.
XYCModel
#
Class for reading and writing XYC files.
Source code in src/dfastio/xyc/models.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
read(file_name: str, num_columns: int = 2, delimiter: str = None, has_header: bool = False) -> linestring.LineString
staticmethod
#
Read lines from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Name of the file to be read. |
required |
num_columns
|
int
|
Number of columns to be read (2 or 3) |
2
|
delimiter
|
str
|
delimiter used in the file. |
None
|
has_header
|
bool
|
whether the file has a header. |
False
|
Returns:
Name | Type | Description |
---|---|---|
L |
LineString
|
shapely.geometry.linestring.LineString Line strings. |
Examples:
>>> from dfastio.xyc.models import XYCModel
>>> path = "examples/data/simple-xyc-file.xyc"
>>> line = XYCModel.read(path, num_columns=3, delimiter=" ", has_header=True)
>>> print(line)
LINESTRING Z (5 6 4, 8 9 7, 11 12 10)
Source code in src/dfastio/xyc/models.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
write(xy: np.ndarray, val: np.ndarray, file_name: str) -> None
staticmethod
#
Write a text file with x, y, and values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy
|
ndarray
|
An N x 2 array containing x and y coordinates. |
required |
val
|
ndarray
|
An N x k array containing values. |
required |
file_name
|
str
|
The name of the file to be written. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Example
>>> from dfastio.xyc.models import XYCModel
>>> import numpy as np
>>> import tempfile
>>> xy = np.array([[1, 2], [4, 5], [7, 8], [10, 11]])
>>> val = np.array([1, 2, 3, 4])
>>> with tempfile.TemporaryDirectory() as tempdir:
... file_name = f"{tempdir}/output.xyc"
... XYCModel.write(xy, val, file_name)
... with open(file_name, "r") as f:
... f.read()
'1.00\t2.00\t1.00\n4.00\t5.00\t2.00\n7.00\t8.00\t3.00\n10.00\t11.00\t4.00\n'
Source code in src/dfastio/xyc/models.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|