Linear Referencing with linref
Overview
The linref library builds on tabular and geospatial libraries pandas and geopandas to provide powerful features for linearly referenced data management, manipulation, and analysis. Using a modern pandas accessor pattern (.lr), linref seamlessly extends DataFrames with linear referencing capabilities while maintaining full compatibility with existing pandas/geopandas workflows.
At its core, linref uses:
LRS (Linear Referencing System) objects to define the schema of your linearly referenced data
EventsData as the underlying computational engine for efficient linear operations
DataFrame accessor pattern (
.lr) for intuitive, pandas-like syntaxOptimized implementations powered by
numpy,shapely, andscipy
Some of the main features of this library include:
Event data engineering - Merge consecutive events with
df.lr.dissolve(), create uniform segments withdf.lr.resegment(), and project point and linear data onto linearly referenced dataData conflation operations - Create relationships between datasets with
df.lr.relate()and aggregate data by attributes, counts, and more using count and length-weighted methodsGeometry operations - Generate geometries from mile markers, extract mile markers from geometries, and perform spatial linear referencing operations
Integration - Combine multiple event datasets into unified linearly referenced frameworks
Prepare and run in-depth analyses - Built-in support for advanced analyses such as high-injury networks, intersection influence areas, and more through simple, well-documented methods
Getting Started
Installation
Install linref using pip:
pip install linref
Basic Concepts
Linear Referencing System (LRS)
An LRS defines the schema of your linearly referenced data by specifying which columns represent:
Key columns
key_col- One or more unique route identifier or grouping columns (e.g., ‘Route’, ‘County’)Chain column
chain_col- An optional column for chain indices that identify contiguous geometry groups within each route, extending standard key columns to avoid non-contiguous groupsMeasure columns - For point events use
loc_col(e.g., ‘Milepost’), for linear eventsbeg_colandend_col(e.g., ‘Begin_Milepost’, ‘End_Milepost’)Geometry columns - For spatial data
geom_coland for spatial data that is m-enabledgeom_m_col(generally m-enabled geometries are prepared and managed bylinref)Closure type
closed- How range endpoints are handled: ‘left’, ‘right’, ‘both’, ‘neither’, or ‘left_mod’/’right_mod’
Documentation
Examples: See the examples section for step-by-step Jupyter notebook tutorials
API Reference: See the API reference for detailed class and method documentation
Release Notes: See the changelog for detailed version history
Contents
- Concepts
- Examples
- API Reference
- Migration Guide: v0.1.x → v1.0
- Key Architectural Changes
- Import Changes
- Setup & LRS Configuration
- Dissolving Events
- Resegmentation (to_windows → resegment)
- Merging / Relating Events
- Union / Integration
- Generating Point Geometries from Mileposts
- Projecting Points onto a Network (Spatial)
- Projecting Linear Geometries onto a Network (Spatial Parallel Projection)
- Sorting
- Accessing Group Data
- Validation
- Quick Reference Table
- Changelog