-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path04_load_data.Rmd
More file actions
32 lines (19 loc) · 2.7 KB
/
04_load_data.Rmd
File metadata and controls
32 lines (19 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Load Data
Adding data to a SpatiaLite database in QGIS is admittedly a little clunky. The good news is that we only need to load each table in once and then it's done.
The overview of the process is that we'll add data to the QGIS interface, then we'll be able to add the data we loaded to the database, then we'll remove the data from QGIS, leaving the data in the databse. Yes, this is annoying. Now let's try it.
## Import Existing Data
Here's how we add data to our database:
1. Add the workshop data to your QGIS canvas. You can drag and drop the .shp files from your computer's file explorer into the QGIS canvas, or you can use the *Data Source Manager* (from the tool bar or the *Layer* menu. All the data we are working with is vector data. With either option, the *Select Transformation* dialog is likely to pop up. Select the transformation that fits your data the best.
1. In the *Browser* panel, right click on your *sfbay.sqlilte* database and select *Import Vector Layer...* The *Import Vector Layers* dialog will open.
1. for the *Source Layer*, select the *Flowlines* data.
1. For the *Table name*, call the table *flowlines* (all lowercase - nameing tables with all lowercase is convention for databases).
1. Change the *Primary key* to *id*. This will make a unique identifier for each row.
1. *Geometry column* is *geom*
1. *Output CRS* is *EPSG:3310 - NAD83 / California Albers* - here we specify the project the data came with, not the projection you want it to have.
1. Check over the table preview and confirm that the *Type* is correct for each of the attribute columns. (Be careful using your scroll wheel in this part of the interface because the dropdowns will scroll if you get close to them, changing the data type.)
1. Click *OK* to add your table to the database.
1. You should now see *flowlines* added to your *Browser* panel in your *sfbay.sqlite* database.
You can repeat this process to add the other two datasets. Call the *WBDHU8_Points_SF* table *centroids* and *WBDHU8_SF* table *watersheds*, but the rest of the parameters should be the same as those we used for the *flowlines* table.
Congratulations! You now have a database with files related to the San Francisco Bay's watersheds!
## Remove Data From the Canvas
Now that our data is in the database, we can remove the files from the map canvas. In the *Layers* panel, select all of the layers by either clicking and draging your mouse across all the files, or selecting the top one, holding down shift, and then clicking the bottom one. Right click on the selected layers. Select *Remove layer*. Confirm that you want to remove these layers by clicking *OK*. This does not delete your data from your computer. It only removes it from the project.