Skip to content

Commit 1dc75f8

Browse files
authored
Replace "the_geom" with "geom" in PostGIS lessons (#9422)
Backports #9417
2 parents 90fcbaa + f193248 commit 1dc75f8

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

docs/training_manual/spatial_databases/geometry.rst

+22-20
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ Try Yourself: :abbr:`★★☆ (Moderate level)`
3434

3535
::
3636

37-
alter table streets add column the_geom geometry;
37+
alter table streets add column geom geometry;
3838
alter table streets add constraint streets_geom_point_chk check
39-
(st_geometrytype(the_geom) = 'ST_LineString'::text OR the_geom IS NULL);
40-
insert into geometry_columns values ('','public','streets','the_geom',2,4326,
39+
(st_geometrytype(geom) = 'ST_LineString'::text OR geom IS NULL);
40+
insert into geometry_columns values ('','public','streets','geom',2,4326,
4141
'LINESTRING');
4242
create index streets_geo_idx
4343
on streets
4444
using gist
45-
(the_geom);
45+
(geom);
4646

4747

4848
Now let's insert a linestring into our streets table. In this case we will
@@ -51,7 +51,7 @@ update an existing street record:
5151
.. code-block:: sql
5252
5353
update streets
54-
set the_geom = 'SRID=4326;LINESTRING(20 -33, 21 -34, 24 -33)'
54+
set geom = 'SRID=4326;LINESTRING(20 -33, 21 -34, 24 -33)'
5555
where streets.id=2;
5656
5757
Take a look at the results in QGIS. (You may need to right-click on the streets
@@ -69,7 +69,7 @@ polygons have at least four vertices, with the last and first being co-located:
6969

7070
.. code-block:: sql
7171
72-
insert into cities (name, the_geom)
72+
insert into cities (name, geom)
7373
values ('Tokyo', 'SRID=4326;POLYGON((10 -10, 5 -32, 30 -27, 10 -10))');
7474
7575
.. note:: A polygon requires double brackets around its coordinate list; this
@@ -78,7 +78,7 @@ polygons have at least four vertices, with the last and first being co-located:
7878

7979
.. code-block:: sql
8080
81-
insert into cities (name, the_geom)
81+
insert into cities (name, geom)
8282
values ('Tokyo Outer Wards',
8383
'SRID=4326;POLYGON((20 10, 20 20, 35 20, 20 10),
8484
(-10 -30, -5 0, -15 -15, -10 -30))'
@@ -116,14 +116,14 @@ Your updated people schema should look something like this:
116116
house_no | integer | not null
117117
street_id | integer | not null
118118
phone_no | character varying |
119-
the_geom | geometry |
119+
geom | geometry |
120120
city_id | integer | not null
121121
Indexes:
122122
"people_pkey" PRIMARY KEY, btree (id)
123123
"people_name_idx" btree (name)
124124
Check constraints:
125-
"people_geom_point_chk" CHECK (st_geometrytype(the_geom) =
126-
'ST_Point'::text OR the_geom IS NULL)
125+
"people_geom_point_chk" CHECK (st_geometrytype(geom) =
126+
'ST_Point'::text OR geom IS NULL)
127127
Foreign-key constraints:
128128
"people_city_id_fkey" FOREIGN KEY (city_id) REFERENCES cities(id)
129129
"people_street_id_fkey" FOREIGN KEY (street_id) REFERENCES streets(id)
@@ -141,23 +141,23 @@ Your updated people schema should look something like this:
141141

142142
::
143143

144-
insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
144+
insert into people (name,house_no, street_id, phone_no, city_id, geom)
145145
values ('Faulty Towers',
146146
34,
147147
3,
148148
'072 812 31 28',
149149
1,
150150
'SRID=4326;POINT(13 -15)');
151151

152-
insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
152+
insert into people (name,house_no, street_id, phone_no, city_id, geom)
153153
values ('IP Knightly',
154154
32,
155155
1,
156156
'071 812 31 28',
157157
1,
158158
'SRID=4326;POINT(18 -24)');
159159

160-
insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
160+
insert into people (name,house_no, street_id, phone_no, city_id, geom)
161161
values ('Rusty Bedsprings',
162162
39,
163163
1,
@@ -234,17 +234,17 @@ To avoid empty geometries, use:
234234

235235
.. code-block:: sql
236236
237-
where not st_isempty(st_intersection(a.the_geom, b.the_geom))
237+
where not st_isempty(st_intersection(a.geom, b.geom))
238238
239239
.. figure:: img/qgis_001.png
240240
:align: center
241241

242242
.. code-block:: sql
243243
244-
select st_intersection(a.the_geom, b.the_geom), b.*
244+
select st_intersection(a.geom, b.geom), b.*
245245
from clip as a, road_lines as b
246-
where not st_isempty(st_intersection(st_setsrid(a.the_geom,32734),
247-
b.the_geom));
246+
where not st_isempty(st_intersection(st_setsrid(a.geom,32734),
247+
b.geom));
248248
249249
.. figure:: img/qgis_002.png
250250
:align: center
@@ -265,9 +265,9 @@ following command:
265265

266266
.. code-block:: sql
267267
268-
select ST_LineFromMultiPoint(st_collect(the_geom)), 1 as id
268+
select ST_LineFromMultiPoint(st_collect(geom)), 1 as id
269269
from (
270-
select the_geom
270+
select geom
271271
from points
272272
order by id
273273
) as foo;
@@ -310,7 +310,9 @@ tablespaces:
310310
311311
CREATE TABLESPACE homespace LOCATION '/home/pg';
312312
313-
When you create a database, you can then specify which tablespace to use e.g.::
313+
When you create a database, you can then specify which tablespace to use e.g.:
314+
315+
.. code-block:: bash
314316
315317
createdb --tablespace=homespace t4a
316318

docs/training_manual/spatial_databases/simple_feature_model.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Let's add a point field to our people table:
4040

4141
.. code-block:: sql
4242
43-
alter table people add column the_geom geometry;
43+
alter table people add column geom geometry;
4444
4545
4646
Add a constraint based on geometry type
@@ -53,8 +53,8 @@ You will notice that the geometry field type does not implicitly specify what
5353
5454
alter table people
5555
add constraint people_geom_point_chk
56-
check(st_geometrytype(the_geom) = 'ST_Point'::text
57-
OR the_geom IS NULL);
56+
check(st_geometrytype(geom) = 'ST_Point'::text
57+
OR geom IS NULL);
5858
5959
This adds a constraint to the table so that it will only accept a point geometry
6060
or a null value.
@@ -69,14 +69,14 @@ sure it has a constraint enforcing geometries to be polygons.
6969
.. admonition:: Answer
7070
:class: dropdown
7171

72-
::
72+
.. code-block: sql
7373
7474
create table cities (id serial not null primary key,
7575
name varchar(50),
76-
the_geom geometry not null);
76+
geom geometry not null);
7777
alter table cities
7878
add constraint cities_geom_point_chk
79-
check (st_geometrytype(the_geom) = 'ST_Polygon'::text );
79+
check (st_geometrytype(geom) = 'ST_Polygon'::text );
8080
8181
8282
@@ -88,7 +88,7 @@ At this point you should also add an entry into the ``geometry_columns`` table:
8888
.. code-block:: sql
8989
9090
insert into geometry_columns values
91-
('','public','people','the_geom',2,4326,'POINT');
91+
('','public','people','geom',2,4326,'POINT');
9292
9393
Why? :kbd:`geometry_columns` is used by certain applications to be aware of
9494
which tables in the database contain geometry data.
@@ -124,7 +124,7 @@ Add an appropriate `geometry_columns` entry for your new cities layer
124124
::
125125

126126
insert into geometry_columns values
127-
('','public','cities','the_geom',2,4326,'POLYGON');
127+
('','public','cities','geom',2,4326,'POLYGON');
128128

129129

130130

@@ -135,7 +135,7 @@ Now that our tables are geo-enabled, we can store geometries in them:
135135

136136
.. code-block:: sql
137137
138-
insert into people (name,house_no, street_id, phone_no, the_geom)
138+
insert into people (name,house_no, street_id, phone_no, geom)
139139
values ('Fault Towers',
140140
34,
141141
3,
@@ -195,7 +195,7 @@ and add layers to your project as usual.
195195
...............................................................................
196196

197197
Formulate a query that shows a person's name, street name and position (from the
198-
the_geom column) as plain text.
198+
geom column) as plain text.
199199

200200
.. admonition:: Answer
201201
:class: dropdown
@@ -204,7 +204,7 @@ the_geom column) as plain text.
204204

205205
select people.name,
206206
streets.name as street_name,
207-
st_astext(people.the_geom) as geometry
207+
st_astext(people.geom) as geometry
208208
from streets, people
209209
where people.street_id=streets.id;
210210

docs/training_manual/spatial_databases/spatial_queries.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ point(X,Y) you can do this with:
1919
2020
select *
2121
from people
22-
where st_distance(the_geom,'SRID=4326;POINT(33 -34)') < 2;
22+
where st_distance(geom,'SRID=4326;POINT(33 -34)') < 2;
2323
2424
Result:
2525

2626
.. code-block:: sql
2727
28-
id | name | house_no | street_id | phone_no | the_geom
28+
id | name | house_no | street_id | phone_no | geom
2929
----+--------------+----------+-----------+---------------+---------------
3030
6 | Fault Towers | 34 | 3 | 072 812 31 28 | 01010008040C0
3131
(1 row)
3232
33-
.. note:: the_geom value above was truncated for space on this page. If you
33+
.. note:: geom value above was truncated for space on this page. If you
3434
want to see the point in human-readable coordinates, try something similar
3535
to what you did in the section "View a point as WKT", above.
3636

@@ -60,7 +60,7 @@ much faster. To create a spatial index on the geometry column use:
6060
CREATE INDEX people_geo_idx
6161
ON people
6262
USING gist
63-
(the_geom);
63+
(geom);
6464
6565
\d people
6666
@@ -77,14 +77,14 @@ Result:
7777
house_no | integer | not null
7878
street_id | integer | not null
7979
phone_no | character varying |
80-
the_geom | geometry |
80+
geom | geometry |
8181
Indexes:
8282
"people_pkey" PRIMARY KEY, btree (id)
83-
"people_geo_idx" gist (the_geom) <-- new spatial key added
83+
"people_geo_idx" gist (geom) <-- new spatial key added
8484
"people_name_idx" btree (name)
8585
Check constraints:
86-
"people_geom_point_chk" CHECK (st_geometrytype(the_geom) = 'ST_Point'::text
87-
OR the_geom IS NULL)
86+
"people_geom_point_chk" CHECK (st_geometrytype(geom) = 'ST_Point'::text
87+
OR geom IS NULL)
8888
Foreign-key constraints:
8989
"people_street_id_fkey" FOREIGN KEY (street_id) REFERENCES streets(id)
9090
@@ -96,11 +96,11 @@ Modify the cities table so its geometry column is spatially indexed.
9696
.. admonition:: Answer
9797
:class: dropdown
9898

99-
::
99+
.. code-block:: psql
100100
101101
CREATE INDEX cities_geo_idx
102102
ON cities
103-
USING gist (the_geom);
103+
USING gist (geom);
104104
105105
106106

docs/user_manual/managing_data_source/supported_data.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ The following example creates a GiST index::
517517
\q to quit
518518

519519
gis_data=# CREATE INDEX sidx_alaska_lakes ON alaska_lakes
520-
gis_data-# USING GIST (the_geom GIST_GEOMETRY_OPS);
520+
gis_data-# USING GIST (geom GIST_GEOMETRY_OPS);
521521
CREATE INDEX
522522
gis_data=# VACUUM ANALYZE alaska_lakes;
523523
VACUUM

0 commit comments

Comments
 (0)