1.2. 准备练习数据(Preparing Exercise Data)

本培训教程附带提供威兰登周边地区的数据作为示例数据。史威兰登镇位于南非西北开普敦的开普敦镇东部,两镇距离 2 小时的路程数据集中的要素名称包含了英语南非荷兰语两种形式。(The sample data provided with the Training Manual refers to the town of Swellendam and its surroundings. Swellendam is located about 2 hours’ east of Cape Town in the Western Cape of South Africa. The dataset contains feature names in both English and Afrikaans.)

尽管大家都可以很容易的使用数据集可能愿意使用来自自己国家故乡数据来练习如果选择这样本地化数据可用于单元3-单元7.2之间的所有练习。但你自己准备的数据可能不大适合后面的单元练习。(Anyone can use this dataset without difficulty, but you may prefer to use data from your own country or home town. If you choose to do so, your localised data will be used in all lessons from Module 3 to Module 7.2. Later modules use more complex data sources which may or may not be available for your region.)


为了让课程组织者经验丰富 的QGIS 用户来创建属于他们本地化示例数据默认数据集由培训手册提供如果希望替换默认数据可以按照下面这些说明来操作。(This process is intended for course conveners, or more experienced QGIS users who wish to create localised sample data sets for their course. Default data sets are provided with the Training Manual, but you may follow these instructions if you wish to replace the default data sets.)


本课程所使用的示例数据集可从这个链接下载。http://qgis.org/downloads/data/training_manual_exercise_data.zip(The sample data used throughout the manual can be downloaded here:http://qgis.org/downloads/data/training_manual_exercise_data.zip

1.2.1. 动手试(Try Yourself)


如果您进行以下的操作,我们会假定您已掌握了较好的 QGIS 知识,是初次作为教材使用。【译者注:如果你想用自己的本地数据,可以参考以下步骤,如果觉得看不懂,就乖乖用官方提供的数据即可。】(These instructions assume you have a good knowledge of QGIS and are not intended to be used as teaching material.)

如果你本地的数据集替换默认数据可以轻松通过内置的 QGIS 工具来完成。但选择使用的区域应该很好的同时包含城市农村地区包含不同等级的道路 不同的区域边界 (如自然保护区农场) 和水域小溪河流等。(If you wish to replace the default data set with localised data for your course, this can easily be done with tools built into QGIS. The region you choose to use should have a good mix of urban and rural areas, containing roads of differing significance, area boundaries (such as nature reserves or farms) and surface water, such as streams and rivers.)

  • 打开一个空白的QGIS工程(Open a new QGIS project)
  • 在“矢量”下拉菜单下,选择“开放街道地图(OpenStreetMap)“->”下载数据”。你可以进一步的手动输入你想设置的区域坐标,或者你可以通过一个图层来设置边界。(In the Vector menu dropdown, select OpenStreetMap -> Download Data. You can then manually enter the co-ordinates of the region you wish to use, or you can use an existing layer to set the co-ordinates.)
  • 选择一个位置来保存输出结果的.osm文件,并点击“确定”:(Choose a location to save the resulting .osm file and click Ok:)


  • 你可以通过“添加矢量图层”按钮来打开刚刚的osm文件,在浏览窗口的文件类型中选择“全部文件”以便能方便找到osm文件。或者你可以直接将osm文件拖拽到QGIS窗口中来打开。(You can then open the .osm file using the Add Vector Layer button. You may need to select All files in the browser window. Alternatively, you can drag and drop the file into the QGIS window.)
  • 在弹出的图层选择窗口中,选择除other_relations 和multilinestrings之外的所有图层。(In the dialog which opens, select all the layers, except the other_relations andmultilinestrings layer:)


点击“确定”后会加载四个符合OSM命名协定的图层,通过缩放工具来查看此矢量数据。(This will load four layers into your map which relate to OSM’s naming conventions (you may need to zoom in/out to see the vector data).)


我们需要这些中提取有用数据它们重命名创建相应shp文件:(We need to extract the useful data from these layers, rename them and create corresponding shape files:)

  • 首先,双击multipolygons图层来打开图层属性对话框。(First, double-click the multipolygons layer to open the Layer properties dialog.)
  • 在通用标签下,点击“查询生成器”来打开查询生成器窗口。(In the General tab, click Query Builder to open the Query builder window.)

我们将提取该图层的下面三个字段:(This layer contains three fields whose data we will need to extract for use throughout the Training Manual:)

  • building
  • natural (specifically, water,主要指水域)
  • landuse

可以测试你选择的区域产生什么样结果如果发现“landuse”没有返回任何结果,就可以随时排除该区域,重新选一块。(You can sample the data your region contains in order to see what kind of results your region will yield. If you find that “landuse” returns no results, then feel free to exclude it.)

需要为每个字段编写筛选器表达式来提取我们需要数据我们将使用“building”字段作为一个例子说明:(You’ll need to write filter expressions for each field to extract the data we need. We’ll use the “building” field as an example here:)

  • 把下面这个表达式输入到文本区域:building != “NULL”   然后点击“测试”来观察本次查询返回了多少条结果。如果返回的结果数很少,你可以打开图层的“属性表”来看一下从OSM获取到了缩少本区域的数据:(Enter the following expression into the text area: building != "NULL" and click Test to see how many results the query will return. If the number of results is small, you may wish to have a look at the layer’s Attribute Table to see what data OSM has returned for your region:)


  • 点击“确定”,你会看到不属于建筑物(building)的要素从地图上隐藏掉了。(Click Ok and you’ll see that the layer elements which are not buildings have been removed from the map.)

我们需要将查询结果保存为shp文件,以便用于本次培训课程:(We now need to save the resulting data as a shapefile for you to use during your course:)

  • 右键点击multipolygons图层,并选择”另存为“。(Right-click the multipolygons layer and select Save As…)
  • 请确认保存文件类型为ESRI shapefile,并将文件保存到你自己的”exercise_data“文件夹下,并将该文件夹放到”epsg4326“的目录下。【译者注:就是放到”/epsg4326/exercise_data/“下面】(Make sure the file type is ESRI Shapefile and save the file in your new exercise_datadirectory, under a directory called “epsg4326”.)
  • 保存过程中确保选中”无样式“,我们会再稍后的课程中添加样式。(Make sure No Symbology is selected (we’ll add symbology as part of the course later on).)
  • 你也可以选中”将保存后的文件添加到地图“(You can also select Add saved file to map.)

一旦查询出为”building”的数据后,你可以通过在查询生成器中替换原来的表达式为以下表达式来查询”natural“和”landuse“的数据:(Once the buildings layer has been added to the map, you can repeat the process for thenatural and landuse fields using the following expressions:)


在执行下一段查询之前请确认已经将之前的查询表达式全部清除!(Make sure you clear the previous filter (via the Layer properties dialog) from themultipolygons layer before proceeding with the next filter expression!)

  • natural: “natural = ‘water’”
  • landuse: “landuse != ‘NULL’”

每一份结果数据集都要保存在”/epsg4326/exercise_data/“目录下面,可以将数据集保存为“水域”“土地利用”等名称。(Each resulting data set should be saved in the “epsg4326” directory in your new exercise_datadirectory (i.e. “water”, “landuse”).)

然后lines和points图层提取以下字段保存相应目录:(You should then extract and save the following fields from the lines and points layers to their corresponding directories:)

  • lines: “highway != ‘NULL’” to roads, and “waterway != ‘NULL’” to rivers
  • points: “place != ‘NULL’” to places

当你完成以上提取工作后,你可以将multipolygons, lines和points图层移除。(Once you have finished extracting the above data, you can remove the multipolygons, linesand points layers.)

现在你会得到一幅类似于下面的地图,样式会变得非常不一样,但这并不重要。(You should now have a map which looks something like this (the symbology will certainly be very different, but that is fine):)


重要的是你现在拥有6个类似于上图所示的图层,并且每个图层都含有数据。(The important thing is that you have 6 layers matching those shown above and that all those layers have some data.)

最后一步从landuse图层创建用于本教程的 spatiallite 文件:(The last step is to create a spatiallite file from the landuse layer for use during the course:)

  • 右键点击landuse图层,并选择“另存为”。(Right-click the landuse layer and select Save as…)
  • 文件类型选择为 spatiallite 格式,并保存到“/epsg4326/”目录下,文件命名为landuse。(Select SpatialLite as the format and save the file as landuse under the “epsg4326” directory.)
  • 点击“确定”。(Click Ok.)
  • 删除“landuse.shp”和与它相关的文件(如果有的话)。(Delete the landuse.shp and its related files (if created).)

1.2.2. 动手试–创建SRTM DEM tiff文件( Try Yourself Create SRTM DEM tiff Files)

在第6单元(创建矢量数据)和第8单元(栅格),你也会用到你选择区域的栅格图像(SRTM DEM)。(For Module 6 (Creating Vector Data) and Module 8 (Rasters), you’ll also need raster images (SRTM DEM) which cover the region you have selected for your course.)

SRTM DEM可以从GIAR-CGI下载。链接为:http://srtm.csi.cgiar.org/。(SRTM DEM can be downloaded from the CGIAR-CGI: http://srtm.csi.cgiar.org/)

你需要将你选择的区域完全覆盖的栅格图像【译者注:如果一块不能完全覆盖,就多下载几块】(You’ll need images which cover the entire region you have chosen to use.)

当你下载了你所需要的文件后(1个或多个),将它们保存在“/epsg4326/exercise_data/raster/SRTM/”目录下(Once you have downloaded the required file(s), they should be saved in the “exercise_data” directory under “raster/SRTM/”.)

在第6单元,第1.2课的时候,会涉及到一个图像,包含三个要求学生需要进行数字化的学校运动场地。因此,你需要对你下载到的SRTM DEM tiff文件进行加工。没有必要必须是学校运动场地,任何三个学校用地类型都可以。(比如不同的校舍,操场和停车场等)(In Module 6, Lesson 1.2 shows close-up images of three school sports fields which students are asked to digitize. You’ll therefore need to reproduce these images using your new SRTM DEM tiff file(s). There is no obligation to use school sports fields: any three school land-use types can be used (e.g. different school buildings, playgrounds or car parks).)

例如示例数据中的图像:(For reference, the images in the example data are:)


1.2.3. 动手试–替换标记(Try Yourself Replace Tokens)

创建本地化数据集的最后一步替换 conf.py 文件中的标记以便相应名称出现本地化版本的培训手册中。(Having created your localised dataset, the final step is to replace the tokens in the conf.py file so that the appropriate names will appear in your localised version of the Training Manual.)

你需要替换的标记有:(The tokens you need to replace are as follows:)

  • majorUrbanName: 默认为“Swellendam”, 用你所选区域的名字对其替换。(majorUrbanName: this defaults to “Swellendam”. Replace with the name of the major town in your region.)
  • schoolAreaType1: 默认为“athletics field”. 用你所选区域中最大的一种学校区域类型替换。(schoolAreaType1: this defaults to “athletics field”. Replace with the name of the largest school area type in your region.)
  • largeLandUseArea: 默认为 “Bontebok National Park”. 用你所选区域中最大的土地利用多边形的名字替换。(largeLandUseArea: this defaults to “Bontebok National Park”. Replace with the name of a large landuse polygon in your region.)
  • srtmFileName: 默认为 srtm_41_19.tif. 用你下载的SRTM DEM file名称替换.(srtmFileName: this defaults to srtm_41_19.tif. Replace this with the filename of your SRTM DEM file.)
  • localCRS: 默认为 WGS 84 / UTM 34S. 用你所选地区的正确的坐标系进行替换。(localCRS: this defaults to WGS 84 / UTM 34S. You should replace this with the correct CRS for your region.)

原作者:Linfiniti Consulting CC.   翻译:数据地图博客


邮箱地址不会被公开。 必填项已用*标注

填写验证码: *