diff --git a/docs/training_manual/spatial_databases/geometry.rst b/docs/training_manual/spatial_databases/geometry.rst index bd0f41d78b7..3d81d1c691f 100644 --- a/docs/training_manual/spatial_databases/geometry.rst +++ b/docs/training_manual/spatial_databases/geometry.rst @@ -194,6 +194,67 @@ Try Yourself: :abbr:`★★★ (Advanced level)` Create city boundaries by computing the minimum convex hull of all addresses for that city and computing a buffer around that area. +.. admonition:: Answer + :class: dropdown + + - Add some people in 'Tokyo Outer Wards' city + + .. code-block:: psql + + INSERT INTO people (name, house_no, street_id, phone_no, city_id, geom) + VALUES ('Bad Aboum', + 57, + 2, + '073 712 31 21', + 2, + 'SRID=4326;POINT(22 18)'); + + INSERT INTO people (name, house_no, street_id, phone_no, city_id, geom) + VALUES ('Pat Atra', + 59, + 2, + '074 712 31 25', + 2, + 'SRID=4326;POINT(23 14)'); + + INSERT INTO people (name, house_no, street_id, phone_no, city_id, geom) + VALUES ('Kat Herin', + 65, + 2, + '074 722 31 28', + 2, + 'SRID=4326;POINT(29 18)'); + + - Create myPolygonTable table + + .. code-block:: psql + + CREATE TABLE myPolygonTable ( + id serial NOT NULL PRIMARY KEY, + city_id int NOT NULL REFERENCES cities(id), + geom geometry NOT NULL + ); + + ALTER TABLE myPolygonTable + ADD CONSTRAINT myPolygonTable_geom_polygon_chk + CHECK (st_geometrytype(geometry) = 'ST_Polygon'::text ); + + - Create and load the convex hulls + + .. code-block:: psql + + INSERT INTO myPolygonTable (city_id, geometry) + SELECT * FROM + ( + SELECT + ROW_NUMBER() over (order by city_id)::integer AS city_id, + ST_CONVEXHULL(ST_COLLECT(geom)) AS geom + FROM people + GROUP BY city_id + ) convexHulls; + + + Access Sub-Objects -------------------------------------------------------------------------------