SpatiaLite logo

Recipe #18
Railway Zones as Buffers

2011 January 28

Previous Slide Table of Contents Next Slide

The problem

This is like a kind of visual conclusion of the latest exercise. The problem now is:
  • create an appropriate Map Layer representing A, B, C, D and E-class zones as previously defined.

QGIS - buffers

CREATE TABLE railway_zones (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  railway_name TEXT NOT NULL,
  zone_name TEXT NOT NULL);

SELECT AddGeometryColumn('railway_zones', 'geometry',
  23032, 'MULTIPOLYGON', 'XY');
We'll start creating a new table:

INSERT INTO railway_zones
  (id, railway_name, zone_name, geometry)
SELECT NULL, name, 'A class [< 1Km]',
  CastToMultiPolygon(
    ST_Buffer(geometry, 1000.0))
FROM railways;
There is very little interest in this INSERT INTO ... SELECT ... statement (again, you already known all this).
Except for the following topic:

INSERT INTO railway_zones
  (id, railway_name, zone_name, geometry)
SELECT NULL, name, 'B class [< 2.5Km]',
  CastToMultiPolygon(
    ST_Difference(
      ST_Buffer(geometry, 2500.0),
      ST_Buffer(geometry, 1000.0)))
FROM railways;

INSERT INTO railway_zones
  (id, railway_name, zone_name, geometry)
SELECT NULL, name, 'C class [< 5Km]',
  CastToMultiPolygon(
    ST_Difference(
      ST_Buffer(geometry, 5000.0),
      ST_Buffer(geometry, 2500.0)))
FROM railways;

INSERT INTO railway_zones
  (id, railway_name, zone_name, geometry)
SELECT NULL, name, 'D class [< 10Km]',
  CastToMultiPolygon(
    ST_Difference(
      ST_Buffer(geometry, 10000.0),
      ST_Buffer(geometry, 5000.0)))
FROM railways;

INSERT INTO railway_zones
  (id, railway_name, zone_name, geometry)
SELECT NULL, name, 'E class [< 20Km]',
  CastToMultiPolygon(
    ST_Difference(
      ST_Buffer(geometry, 20000.0),
      ST_Buffer(geometry, 10000.0)))
FROM railways;
Creating any further zone isn't much more difficult.
You can now perform a simple visual check using QGIS. And that's all.

Previous Slide Table of Contents Next Slide

CC-BY-SA logo Author: Alessandro Furieri a.furieri@lqt.it
This work is licensed under the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.

GNU logo Permission is granted to copy, distribute and/or modify this document under the terms of the
GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.