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.

Shared operations#

Like every shapelib type, Lines also has:

  • CRS: to_utm(), to_wgs84(), to_original_crs() and the temp_crs(...) context manager (see Work in meters);

  • table utilities: add_index(), has_column(), get_element(), remove_column(), remove_rows_by_column_values();

  • cleaning: remove_missing_geometries(), multi_to_single_geometries(), check_columns_encoding();

  • selection: intersect_with_geom(), filter_by_geom_type();

  • I/O: save() to local or cloud destinations.

See also

The higher-level line operations — grouping, deduplication, merging fragments, interlines — live in Line tools.