When working with geospatial data, it's important to represent not just areas (polygons) but also paths, routes, or edges. That’s where the LineString type comes in. ClickHouse supports LineString as a simple way to store a line made up of multiple points, very useful for roads, or movement paths.
What is a LineString?
A LineString is a series of connected points, forming a line, like a route on a map.
LineString Characterstics
· Internally stored as Array(Point)
· A Point is a pair of coordinates (x, y)
· Unlike Ring, it does not close back to the starting point
Let’s take a real world example to understand LineString better.
CREATE DATABASE IF NOT EXISTS demo_db; CREATE TABLE demo_db.road_paths ( road_name String, path LineString ) ENGINE = Memory();
Here:
· road_name: Name of the road or route
· path: A LineString (series of points forming a path)
Let’s define a road that makes 3 turns.
From (0,0) → (10,0) → (10,10) → (0,10)
INSERT INTO demo_db.road_paths VALUES ( 'Main Street', [(0, 0), (10, 0), (10, 10), (0, 10)] );
Let's view the line string.
SELECT road_name, path, toTypeName(path) AS type FROM demo_db.road_paths;
krishna :) SELECT road_name, path, toTypeName(path) AS type FROM demo_db.road_paths; SELECT road_name, path, toTypeName(path) AS type FROM demo_db.road_paths Query id: f57ba1aa-4e68-4d93-a4d3-9718b87f6429 ┌─road_name───┬─path──────────────────────────┬─type───────┐ 1. │ Main Street │ [(0,0),(10,0),(10,10),(0,10)] │ LineString │ └─────────────┴───────────────────────────────┴────────────┘ 1 row in set. Elapsed: 0.001 sec.
Previous Next Home
No comments:
Post a Comment