Lines#
Lines represents a set of LineString geometries — in practice,
planting lines. It subclasses geopandas.GeoDataFrame, so everything
geopandas offers is still there; shapelib adds the operations below.
from shapelib import read_file
lines = read_file("planting_lines.shp")
Measuring and filtering#
lines.calculate_length() # geodesic length per line, in a "length" column
total = lines.get_total_length()
lines.filter_by_length(10) # drop lines shorter than the threshold
calculate_length measures on the WGS 84 ellipsoid, so the values are
accurate no matter the CRS of the file.
Transforming geometries#
lines.reduce_length(2.0) # trim the tips of every line
lines.simplify_lines(0.1) # simplify vertices
polygons = lines.buffer_m(1.5) # buffer into Polygons (meters)
# Split lines between those touching and not touching polygons
touching, free = lines.split_by_touching_polygons(fields)
Line spacing#
Planting lines usually come with (or need) spacing information:
lines.check_spacement_info() # find a spacing column in the table
spacing = lines.estimate_line_spacing() # estimate it from the geometry
Rasters#
Lines converts to and from raster masks, which is how detection
models produce and consume them:
lines = Lines.from_mask(mask, dataset_reader=orto)
mask = lines.to_mask(dataset_reader=orto)
See Raster converters for the full conversion pipeline.