line_metric
Compute a set of line metrics for every row of the gdf.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
GeoDataFrame
|
The input GeoDataFrame. |
required |
metrics
|
Tuple[str, ...]
|
A Tuple/List of line metrics. |
required |
parallel
|
bool
|
Flag whether to use parallel apply operations when computing the diversities. |
True
|
num_processes
|
int
|
The number of processes to use when parallel=True. If -1, this will use all available cores. |
1
|
col_prefix
|
str
|
Prefix for the new column names. |
None
|
create_copy
|
bool
|
Flag whether to create a copy of the input gdf or not. |
True
|
Note
Allowed shape metrics are:
tortuosity
average_turning_angle
length
major_axis_len
minor_axis_len
major_axis_angle
minor_axis_angle
Raises:
Type | Description |
---|---|
ValueError
|
If an illegal metric is given. |
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: The input geodataframe with computed shape metric columns added. |
Examples:
>>> from shapely.geometry import LineString
>>> from histolytics.spatial_geom.line_metrics import line_metric
>>> import geopandas as gpd
>>> lines = [
... LineString([(i, i) for i in range(12)]),
... LineString([(i, 0 if i % 2 == 0 else 1) for i in range(12)]),
... LineString([(0, i) for i in range(12)]),
>>> ]
>>> gdf = gpd.GeoDataFrame(geometry=lines)
>>> gdf = line_metric(gdf, metrics=["tortuosity", "length"], parallel=True)
>>> print(gdf.head(3))
geometry tortuosity length
0 LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6,... 1.000000 15.556349
1 LINESTRING (0 0, 1 1, 2 0, 3 1, 4 0, 5 1, 6 0,... 1.408406 15.556349
2 LINESTRING (0 0, 0 1, 0 2, 0 3, 0 4, 0 5, 0 6,... 1.000000 11.000000
Source code in src/histolytics/spatial_geom/line_metrics.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|