20. 回答シート

20.1. Results For 最初のレイヤを追加

20.1.1. basic 準備

道路をシンボル化した多数のラインが見えます。このラインは基本マップを作るのにちょうど今ロードしたベクターレイヤ内にあります。

テキストに戻る

20.2. Results For インタフェースのあらまし

20.2.1. basic あらまし (パート 1)

Refer back to the image showing the interface layout and check that you remember the names and functions of the screen elements.

テキストに戻る

20.2.2. basic あらまし (パート 2)

  1. 名前を付けて保存

  2. レイヤにズーム

  3. ヘルプ

  4. 描画 オン/オフ

  5. ラインを計測

テキストに戻る

20.3. Results For ベクターデータで作業

20.3.1. basic Shapefiles

あなたのマップには5つのレイヤができます:

  • 場所

  • 水系

  • 建物

  • 河川 および

  • 道路.

テキストに戻る

20.3.2. basic データベース

すべてのベクターレイヤはマップにロードしておく必要があります。まだ見た目は素敵ではないかもしれませんが(配色は後ほど見直します)。

テキストに戻る

20.4. Results For Symbology

20.4.1. basic

  • 色が期待通りに変わっているか確認してください。

  • 現時点では 水系 レイヤを変えるだけで十分です。下記はその例ですが、選んだ色によっては違って見えるかもしれません。

../../../_images/answer_water_blue.png

ノート

他のレイヤに煩わされずに一度にひとつのレイヤだけで作業したい場合、レイヤ一覧内のその名前の隣にあるチェックボックス内をクリックしてレイヤを非表示にできます。ボックスが空の場合にレイヤは非表示です。

テキストに戻る

20.4.2. basic シンボルの構造

これであなたのマップはこのように見えていると思います:

../../../_images/answer_symbology1.png

あなたが初心者レベルのユーザであれば、ここで止めた方が良いかもしれません。

  • 上のメソッドを使って残りのレイヤすべての色とスタイルを変更します。

  • オブジェクトにはできるだけ本来の色を使うようにしてください。たとえば、道路は赤や青ではなく、グレイまたは黒であるべきです。

  • Also feel free to experiment with different Fill Style and Border Style settings for the polygons.

テキストに戻る

20.4.3. moderate シンボルレイヤ

  • 建物 レイヤは好きなようにカスタマイズできますが、マップ上で離れている異なるレイヤに容易に伝えられるものでなければなりません。

こちらがサンプルです:

../../../_images/answer_buildings_symbology.png

テキストに戻る

20.4.4. moderate シンボルのレベル

必要なシンボルを作るには2つのシンボルレイヤが必要です:

../../../_images/answer_road_symbology.png

いちばん下のシンボルレイヤは幅広の黄色の実線です。その先頭にはやや狭いグレーの実線があります。

  • もしあなたのシンボルレイヤが上記に似てはいるが欲しい結果が得られていない場合は、あなたのシンボルレベルが次のように見えるかどうかチェックしてください:

    ../../../_images/answer_road_symbol_levels.png
  • これであなたのマップは次のように見えるようになったはずです:

    ../../../_images/target_road_symbology.png

テキストに戻る

20.4.5. hard シンボルレベル

  • あなたのシンボルレベルをこれらの値に合わせてください:

../../../_images/answer_road_symbol_layers.png
  • 値をいろいろ試して様々な結果を取得してみてください。

  • 次の演習を続ける前にオリジナルのマップを再度オープンしてください。

テキストに戻る

20.5. Results For 属性データ

20.5.1. basic 属性データ

The NAME field is the most useful to show as labels. This is because all its values are unique for every object and are very unlikely to contain NULL values. If your data contains some NULL values, do not worry as long as most of your places have names.

テキストに戻る

20.6. Results For ラベルツール

20.6.1. moderate ラベルのカスタマイズ (パート 1)

Your map should now show the marker points and the labels should be offset by 2.0 mm: The style of the markers and labels should allow both to be clearly visible on the map:

../../../_images/customised_labels_one.png

テキストに戻る

20.6.2. moderate ラベルのカスタマイズ (パート 2)

One possible solution has this final product:

../../../_images/possible_outcome_map.png

To arrive at this result:

  • Use a font size of 10, a Label distance of 1,5 mm, Symbol width and Symbol size of 3.0 mm.

  • In addition, this example uses the Wrap label on character option:

    ../../../_images/wrap_character_settings.png
  • Enter a space in this field and click Apply to achieve the same effect. In our case, some of the place names are very long, resulting in names with multiple lines which is not very user friendly. You might find this setting to be more appropriate for your map.

テキストに戻る

20.6.3. hard Using Data Defined Settings

  • Still in edit mode, set the FONT_SIZE values to whatever you prefer. The example uses 16 for towns, 14 for suburbs, 12 for localities and 10 for hamlets.

  • 編集モードを抜ける前に忘れずに変更を保存してください。

  • Return to the Text formatting options for the places layer and select FONT_SIZE in the Attribute field of the font size data override dropdown:

    ../../../_images/font_size_override.png

    Your results, if using the above values, should be this:

    ../../../_images/font_override_results.png

テキストに戻る

20.7. Results For 分類

20.7.1. moderate 分類を改善

  • Use the same method as in the first exercise of the lesson to get rid of the borders:

    ../../../_images/gradient_map_no_pen.png

The settings you used might not be the same, but with the values Classes = 6 and Mode = Natural Breaks (Jenks) (and using the same colors, of course), the map will look like this:

../../../_images/gradient_map_new_mode.png

テキストに戻る

20.8. Results For 新しいベクターデータセットの作成

20.8.1. basic デジタイジング

The symbology doesn’t matter, but the results should look more or less like this:

../../../_images/routes_layer_result.png

テキストに戻る

20.8.2. moderate トポロジー: リングツールを追加

正確な形状は重要ではありませんが、あなたの地物の中央には穴が空くことになります。こちらのように。

../../../_images/ring_tool_result.png
  • Undo your edit before continuing with the exercise for the next tool.

テキストに戻る

20.8.3. moderate Topology: パートツールを追加

  • 最初に Bontebok National Park を選択します:

../../../_images/park_selected.png
  • 新しいパートを追加:

../../../_images/new_park_area.png
  • Undo your edit before continuing with the exercise for the next tool.

テキストに戻る

20.8.4. hard 地物をマージ

  • 選択した地物のマージ ツールを使う際には、最初にマージしたいポリゴンを両方選んでください。

  • Use the feature with the OGC_FID of 1 as the source of your attributes (click on its entry in the dialog, then click the Take attributes from selected feature button):

ノート

If you’re using a different dataset, it is highly likely that your
original polygon’s OGC_FID will not be 1. Just choose the feature which has an OGC_FID.
../../../_images/merge_feature_dialog.png

ノート

Using the Merge Attributes of Selected Features tool will keep the geometries distinct, but give them the same attributes.

テキストに戻る

20.8.5. moderate フォーム

For the TYPE, there is obviously a limited amount of types that a road can be, and if you check the attribute table for this layer, you’ll see that they are predefined.

  • ウィジェットを バリューマップ にセットして :guilabel:` レイヤからデータをロード` をクリックしてください。

  • Select roads in the Label dropdown and highway for both the Value and Description options:

    ../../../_images/value_map_settings.png
  • Ok を3回クリックしてください。

  • If you use the Identify tool on a street now while edit mode is active, the dialog you get should look like this:

    ../../../_images/highway_as_value_map.png

テキストに戻る

20.9. Results For ベクター分析

20.9.1. moderate OSM データから自分用のレイヤを抽出

For the purpose of this exercise, the OSM layers which we are interested in are multipolygons and lines. The multipolygons layer contains the data we need in order to produce the houses, schools and restaurants layers. The lines layer contains the roads dataset.

クエリビルダー はレイヤプロパティにあります:

../../../_images/query_builder.png

Using the Query Builder against the multipolygons layer, create the following queries for the houses, schools, restaurants and residential layers:

../../../_images/houses_query.png ../../../_images/schools_query.png ../../../_images/restaurants_query.png

Once you have entered each query, click OK. You’ll see that the map updates to show only the data you have selected. Since you need to use again the multipolygons data from the OSM dataset, at this point, you can use one of the following methods:

  • Rename the filtered OSM layer and re-import the layer from osm_data.osm, OR
  • Duplicate the filtered layer, rename the copy, clear the query and create your new query in the Query Builder.

ノート

Although OSM’s building field has a house value, the coverage in your area - as in ours - may not be complete. In our test region, it is therefore more accurate to exclude all buildings which are defined as anything other than house. You may decide to simply include buildings which are defined as house and all other values that have not a clear meaning like yes.

To create the roads layer, build this query against OSM’s lines layer:

../../../_images/roads_query.png

You should end up with a map which looks similar to the following:

../../../_images/osm_queries_result.png

テキストに戻る

20.9.2. basic 高校からの距離

  • あなたのバッファダイアログはこのように見えるはずです:

    ../../../_images/schools_buffer_setup.png

    バッファ距離1000 メーターです (すなわち 1 キロメーター)。

  • The Segments to approximate value is set to 20. This is optional, but it’s recommended, because it makes the output buffers look smoother. Compare this:

    ../../../_images/schools_buffer_5.png

    To this:

    ../../../_images/schools_buffer_20.png

The first image shows the buffer with the Segments to approximate value set to 5 and the second shows the value set to 20. In our example, the difference is subtle, but you can see that the buffer’s edges are smoother with the higher value.

Back to text

20.9.3. basic レストランからの距離

新しい houses_restaurants_500m レイヤを作成するために、2ステップの手順を実施します:

  • 最初に、レストランの周囲に500m のバッファを作成し、マップにレイヤを追加します:

    ../../../_images/restaurants_buffer.png ../../../_images/restaurants_buffer_result.png
  • 次に、そのバッファ領域内の建物を選択します:

    ../../../_images/select_within_restaurants.png
  • そして選んだものを新しい houses_restaurants_500m レイヤに保存します:

    ../../../_images/save_selection_restaurants.png

これであなたのマップには道路から50m 以内、学校から1km 以内、そしてレストランから500m 以内の建物だけが表示されます:

../../../_images/restaurant_buffer_result.png

テキストに戻る

20.10. Results For ラスタ分析

20.10.1. basic 角度を計算

  • Set your DEM (Terrain analysis) dialog up like this:

    ../../../_images/answer_dem_aspect.png

結果:

../../../_images/answer_aspect_result.png

テキストに戻る

20.10.2. moderate 傾斜を計算 (less than 2 and 5 degrees)

  • Set your Raster calculator dialog up like this:

    ../../../_images/answer_raster_calculator_slope.png
  • For the 5 degree version, replace the 2 in the expression and file name with 5.

結果:

  • 2 度:

    ../../../_images/answer_2degree_result.png
  • 5 度:

    ../../../_images/answer_5degree_result.png

テキストに戻る

20.11. Results For 分析を完了させる

20.11.1. moderate ラスタからベクタ

  • Open the Query Builder by right-clicking on the all_terrain layer in the Layers list, select the General tab.
  • Then build the query "suitable" = 1.
  • Click OK to filter out all the polygons where this condition isn’t met.

オリジナルのラスタ上で閲覧するとその領域は完全にオーバーラップされるはずです:

../../../_images/polygonize_raster.png
  • You can save this layer by right-clicking on the all_terrain layer in the Layers list and choosing Save As..., then continue as per the instructions.

テキストに戻る

20.11.2. moderate 結果を精査

You may notice that some of the buildings in your new_solution layer have been “sliced” by the Intersect tool. This shows that only part of the building - and therefore only part of the property - lies on suitable terrain. We can therefore sensibly eliminate those buildings from our dataset

テキストに戻る

20.11.3. moderate 分析を改善する

現時点ではあなたの分析は次のように見えるはずです:

../../../_images/new_solution_example.png

Consider a circular area, continuous for 100 meters in all directions.

../../../_images/circle_100.png

If it is greater than 100 meters in radius, then subtracting 100 meters from its size (from all directions) will result in a part of it being left in the middle.

../../../_images/circle_with_remainder.png

Therefore, you can run an interior buffer of 100 meters on your existing suitable_terrain vector layer. In the output of the buffer function, whatever remains of the original layer will represent areas where there is suitable terrain for 100 meters beyond.

To demonstrate:

  • Go to Vector ‣ Geoprocessing Tools ‣ Buffer(s) to open the Buffer(s) dialog.

  • このようにセットアップします:

    ../../../_images/suitable_terrain_buffer.png
  • Use the suitable_terrain layer with 10 segments and a buffer distance of -100. (The distance is automatically in meters because your map is using a projected CRS.)

  • Save the output in exercise_data/residential_development/ as suitable_terrain_continuous100m.shp.

  • 必要に応じて、あなたのオリジナルの suitable_terrain レイヤの上に新しいレイヤを移動してください。

作業結果は次のように見えるはずです:

../../../_images/suitable_buffer_results.png
  • Now use the Select by Location tool (Vector ‣ Research Tools ‣ Select by location).

  • このようにセットアップします:

    ../../../_images/select_by_location.png
  • Select features in new_solution that intersect features in suitable_terrain_continuous100m.shp.

結果はこちらです:

../../../_images/buffer_select_result.png

The yellow buildings are selected. Although some of the buildings fall partly outside the new suitable_terrain_continuous100m layer, they lie well within the original suitable_terrain layer and therefore meet all of our requirements.

  • Save the selection under exercise_data/residential_development/ as final_answer.shp.

テキストに戻る

20.12. Results For WMS

20.12.1. basic Adding Another WMS Layer

Your map should look like this (you may need to re-order the layers):

../../../_images/geology_layer_result.png

Back to text

20.12.2. moderate Adding a New WMS Server

  • Use the same approach as before to add the new server and the appropriate layer as hosted on that server:

    ../../../_images/add_ogc_server.png ../../../_images/add_bluemarble_layer.png
  • If you zoom into the Swellendam area, you’ll notice that this dataset has a low resolution:

../../../_images/low_resolution_dataset.png

Therefore, it’s better not to use this data for the current map. The Blue Marble data is more suitable at global or national scales.

Back to text

20.12.3. moderate Finding a WMS Server

You may notice that many WMS servers are not always available. Sometimes this is temporary, sometimes it is permanent. An example of a WMS server that worked at the time of writing is the World Mineral Deposits WMS at http://apps1.gdr.nrcan.gc.ca/cgi-bin/worldmin_en-ca_ows. It does not require fees or have access constraints, and it is global. Therefore, it does satisfy the requirements. Keep in mind, however, that this is merely an example. There are many other WMS servers to choose from.

Back to text

20.13. Results For Database Concepts

20.13.1. basic Address Table Properties

For our theoretical address table, we might want to store the following properties:

House Number
Street Name
Suburb Name
City Name
Postcode
Country

When creating the table to represent an address object, we would create columns to represent each of these properties and we would name them with SQL-compliant and possibly shortened names:

house_number
street_name
suburb
city
postcode
country

Back to text

20.13.2. basic Normalising the People Table

The major problem with the people table is that there is a single address field which contains a person’s entire address. Thinking about our theoretical address table earlier in this lesson, we know that an address is made up of many different properties. By storing all these properties in one field, we make it much harder to update and query our data. We therefore need to split the address field into the various properties. This would give us a table which has the following structure:

id |     name      | house_no |  street_name   |    city    |   phone_no
 --+---------------+----------+----------------+------------+-----------------
 1 | Tim Sutton    |     3    | Buirski Plein  | Swellendam | 071 123 123
 2 | Horst Duester |     4    | Avenue du Roix | Geneva     | 072 121 122

ノート

In the next section, you will learn about Foreign Key relationships which could be used in this example to further improve our database’s structure.

Back to text

20.13.3. moderate Further Normalisation of the People Table

Our people table currently looks like this:

id |     name     | house_no | street_id |  phone_no
---+--------------+----------+-----------+-------------
 1 | Horst Duster |        4 |         1 | 072 121 122

The street_id column represents a ‘one to many’ relationship between the people object and the related street object, which is in the streets table.

One way to further normalise the table is to split the name field into first_name and last_name:

id | first_name | last_name  | house_no | street_id |  phone_no
---+------------+------------+----------+-----------+------------
 1 |    Horst   |   Duster   |     4    |     1     | 072 121 122

We can also create separate tables for the town or city name and country, linking them to our people table via ‘one to many’ relationships:

id | first_name | last_name | house_no | street_id | town_id | country_id
---+------------+-----------+----------+-----------+---------+------------
 1 |    Horst   |   Duster  |     4    |     1     |    2    |     1

An ER Diagram to represent this would look like this:

../../../_images/er-people-normalised-example.png

Back to text

20.13.4. moderate Create a People Table

The SQL required to create the correct people table is:

create table people (id serial not null primary key,
                     name varchar(50),
                     house_no int not null,
                     street_id int not null,
                     phone_no varchar null );

The schema for the table (enter \d people) looks like this:

Table "public.people"

Column     |         Type          |                      Modifiers
-----------+-----------------------+-------------------------------------
id         | integer               | not null default
           |                       | nextval('people_id_seq'::regclass)
name       | character varying(50) |
house_no   | integer               | not null
street_id  | integer               | not null
phone_no   | character varying     |
Indexes:
  "people_pkey" PRIMARY KEY, btree (id)

ノート

For illustration purposes, we have purposely omitted the fkey constraint.

Back to text

20.13.5. basic The DROP Command

The reason the DROP command would not work in this case is because the people table has a Foreign Key constraint to the streets table. This means that dropping (or deleting) the streets table would leave the people table with references to non-existent streets data.

ノート

It is possible to ‘force’ the streets table to be deleted by using the CASCADE command, but this would also delete the people and any other table which had a relationship to the streets table. Use with caution!

Back to text

20.13.6. basic Insert a New Street

The SQL command you should use looks like this (you can replace the street name with a name of your choice):

insert into streets (name) values ('Low Road');

Back to text

20.13.7. moderate Add a New Person With Foreign Key Relationship

Here is the correct SQL statement:

insert into streets (name) values('Main Road');
insert into people (name,house_no, street_id, phone_no)
  values ('Joe Smith',55,2,'072 882 33 21');

If you look at the streets table again (using a select statement as before), you’ll see that the id for the Main Road entry is 2.

That’s why we could merely enter the number 2 above. Even though we’re not seeing Main Road written out fully in the entry above, the database will be able to associate that with the street_id value of 2.

ノート

If you have already added a new street object, you might find that the new Main Road has an ID of 3 not 2.

Back to text

20.13.8. moderate Return Street Names

Here is the correct SQL statement you should use:

select count(people.name), streets.name
from people, streets
where people.street_id=streets.id
group by streets.name;

Result:

count |    name
------+-------------
    1 | Low Street
    2 | High street
    1 | Main Road
(3 rows)

ノート

You will notice that we have prefixed field names with table names (e.g. people.name and streets.name). This needs to be done whenever the field name is ambiguous (i.e. not unique across all tables in the database).

Back to text

20.14. Results For Spatial Queries

20.14.1. basic The Units Used in Spatial Queries

The units being used by the example query are degrees, because the CRS that the layer is using is WGS 84. This is a Geographic CRS, which means that its units are in degrees. A Projected CRS, like the UTM projections, is in meters.

Remember that when you write a query, you need to know which units the layer’s CRS is in. This will allow you to write a query that will return the results that you expect.

Back to text

20.14.2. basic Creating a Spatial Index

CREATE INDEX cities_geo_idx
  ON cities
  USING gist (the_geom);

Back to text

20.15. Results For Geometry Construction

20.15.1. moderate Creating Linestrings

alter table streets add column the_geom geometry;
alter table streets add constraint streets_geom_point_chk check
     (st_geometrytype(the_geom) = 'ST_LineString'::text OR the_geom IS NULL);
insert into geometry_columns values ('','public','streets','the_geom',2,4326,
     'LINESTRING');
create index streets_geo_idx
  on streets
  using gist
  (the_geom);

Back to text

20.15.2. moderate Linking Tables

delete from people;
alter table people add column city_id int not null references cities(id);

(capture cities in QGIS)

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
   values ('Faulty Towers',
           34,
           3,
           '072 812 31 28',
           1,
           'SRID=4326;POINT(33 33)');

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
   values ('IP Knightly',
           32,
           1,
           '071 812 31 28',
           1,F
           'SRID=4326;POINT(32 -34)');

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)
   values ('Rusty Bedsprings',
           39,
           1,
           '071 822 31 28',
           1,
           'SRID=4326;POINT(34 -34)');

If you’re getting the following error message:

ERROR:  insert or update on table "people" violates foreign key constraint
        "people_city_id_fkey"
DETAIL: Key (city_id)=(1) is not present in table "cities".

then it means that while experimenting with creating polygons for the cities table, you must have deleted some of them and started over. Just check the entries in your cities table and use any id which exists.

テキストに戻る

20.16. Results For 簡易機能モデル

20.16.1. moderate Populating Tables

create table cities (id serial not null primary key,
                     name varchar(50),
                     the_geom geometry not null);
 alter table cities
 add constraint cities_geom_point_chk
 check (st_geometrytype(the_geom) = 'ST_Polygon'::text );

テキストに戻る

20.16.2. moderate Populate the Geometry_Columns Table

insert into geometry_columns values
      ('','public','cities','the_geom',2,4326,'POLYGON');

テキストに戻る

20.16.3. hard ジオメトリの追加

select people.name,
       streets.name as street_name,
       st_astext(people.the_geom) as geometry
from   streets, people
where  people.street_id=streets.id;

Result:

     name     | street_name |   geometry
--------------+-------------+---------------
 Roger Jones  | High street |
 Sally Norman | High street |
 Jane Smith   | Main Road   |
 Joe Bloggs   | Low Street  |
 Fault Towers | Main Road   | POINT(33 -33)
(5 rows)

ご覧のとおり、私たちの制限ではデータベースへの null の追加を認めています。

テキストに戻る