liveBook · Manning

Line segment

As explained in Just Use Postgres!

A line segment is a finite linear geometric object bounded by two endpoints or represented as part of a connected path.

A line segment represents a bounded linear object defined by two points and a length. In geospatial data, roads and trails appear as connected sequences of segments, commonly stored as LineString geometries. section 10.1

PostGIS lets you inspect these objects, measure their lengths, and test whether they share points with another geometry. Roads, rivers, highways, and similar linear features can be queried from an OSM-derived line table. section 10.5.3

Finding roads within or crossing Miami

A query selects primary and secondary LineString roads that intersect Miami’s boundary, then reports each geometry’s point count and length in meters and feet. Results can be ordered to show the longest roads. section 10.5.3

Listing 10.22 Finding the top 10 roads within or crossing Miami
WITH miami AS (
  SELECT way AS boundaries
  FROM florida.planet_osm_polygon
  WHERE name = 'Miami' AND place = 'city'
)
SELECT l.name, l.highway, 
  ST_NPoints(l.way) AS points_number,
  round(ST_Length(l.way)) AS len_meters,
  round(ST_Length(l.way) * 3.28084) AS len_feet
FROM florida.planet_osm_line l
JOIN miami m ON ST_Intersects(l.way, m.boundaries)  
WHERE l.highway IN ('primary', 'secondary')
ORDER BY len_meters DESC LIMIT 10;

Run the supplied SQL listing to connect line-segment geometry with city-boundary filtering, road classification, point counts, and length conversion. section 10.5.3

How Just Use Postgres! covers it

How deep it goes
Explains segment representation and demonstrates length and intersection queries, without developing geometric theory.
Examples
Uses OSM-derived highways, roads, rivers, Miami boundaries, road classifications, point counts, and measured lengths.
What it assumes
Assumes geospatial tables and PostGIS functions, while introducing roads and trails as sequences of point-defined segments.
What you can do after
Apply it via PostGIS to group road types, measure LineStrings, and find geometries intersecting a city boundary.
How it connects
Connects line segments with LineString geometry, points, polygons, roads, trails, PostGIS, and spatial intersection.

Also explained in

Compare how 4 books explain line segment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.