@@ -34,15 +34,15 @@ Try Yourself: :abbr:`★★☆ (Moderate level)`
34
34
35
35
::
36
36
37
- alter table streets add column the_geom geometry;
37
+ alter table streets add column geom geometry;
38
38
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,
41
41
'LINESTRING');
42
42
create index streets_geo_idx
43
43
on streets
44
44
using gist
45
- (the_geom );
45
+ (geom );
46
46
47
47
48
48
Now let's insert a linestring into our streets table. In this case we will
@@ -51,7 +51,7 @@ update an existing street record:
51
51
.. code-block :: sql
52
52
53
53
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)'
55
55
where streets.id=2;
56
56
57
57
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:
69
69
70
70
.. code-block :: sql
71
71
72
- insert into cities (name, the_geom )
72
+ insert into cities (name, geom )
73
73
values ('Tokyo', 'SRID=4326;POLYGON((10 -10, 5 -32, 30 -27, 10 -10))');
74
74
75
75
.. 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:
78
78
79
79
.. code-block :: sql
80
80
81
- insert into cities (name, the_geom )
81
+ insert into cities (name, geom )
82
82
values ('Tokyo Outer Wards',
83
83
'SRID=4326;POLYGON((20 10, 20 20, 35 20, 20 10),
84
84
(-10 -30, -5 0, -15 -15, -10 -30))'
@@ -116,14 +116,14 @@ Your updated people schema should look something like this:
116
116
house_no | integer | not null
117
117
street_id | integer | not null
118
118
phone_no | character varying |
119
- the_geom | geometry |
119
+ geom | geometry |
120
120
city_id | integer | not null
121
121
Indexes:
122
122
"people_pkey" PRIMARY KEY, btree (id)
123
123
"people_name_idx" btree (name)
124
124
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)
127
127
Foreign-key constraints:
128
128
"people_city_id_fkey" FOREIGN KEY (city_id) REFERENCES cities(id)
129
129
"people_street_id_fkey" FOREIGN KEY (street_id) REFERENCES streets(id)
@@ -141,23 +141,23 @@ Your updated people schema should look something like this:
141
141
142
142
::
143
143
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 )
145
145
values ('Faulty Towers',
146
146
34,
147
147
3,
148
148
'072 812 31 28',
149
149
1,
150
150
'SRID=4326;POINT(13 -15)');
151
151
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 )
153
153
values ('IP Knightly',
154
154
32,
155
155
1,
156
156
'071 812 31 28',
157
157
1,
158
158
'SRID=4326;POINT(18 -24)');
159
159
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 )
161
161
values ('Rusty Bedsprings',
162
162
39,
163
163
1,
@@ -234,17 +234,17 @@ To avoid empty geometries, use:
234
234
235
235
.. code-block :: sql
236
236
237
- where not st_isempty(st_intersection(a.the_geom , b.the_geom ))
237
+ where not st_isempty(st_intersection(a.geom , b.geom ))
238
238
239
239
.. figure :: img/qgis_001.png
240
240
:align: center
241
241
242
242
.. code-block :: sql
243
243
244
- select st_intersection(a.the_geom , b.the_geom ), b.*
244
+ select st_intersection(a.geom , b.geom ), b.*
245
245
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 ));
248
248
249
249
.. figure :: img/qgis_002.png
250
250
:align: center
@@ -265,9 +265,9 @@ following command:
265
265
266
266
.. code-block :: sql
267
267
268
- select ST_LineFromMultiPoint(st_collect(the_geom )), 1 as id
268
+ select ST_LineFromMultiPoint(st_collect(geom )), 1 as id
269
269
from (
270
- select the_geom
270
+ select geom
271
271
from points
272
272
order by id
273
273
) as foo;
@@ -310,7 +310,9 @@ tablespaces:
310
310
311
311
CREATE TABLESPACE homespace LOCATION '/home/pg';
312
312
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
314
316
315
317
createdb --tablespace=homespace t4a
316
318
0 commit comments