-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPGISdata_R_attempt.qmd
118 lines (78 loc) · 2.74 KB
/
PPGISdata_R_attempt.qmd
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
title: "import_cusensdata_test"
author: "Erika"
format: html
editor: visual
---
```{r}
#trying stuff with Chapter 23 now:
#NB: this was able to plot just Norway on its own, with Fylke:
#23.1.3 Other vector filess
library(sf)
# https://kartkatalog.geonorge.no/metadata/norske-fylker-og-kommuner-illustrasjonsdata-2021-klippet-etter-kyst/f08fca3c-33ee-49b9-be9f-028ebba5e460)
#downloaded it from GeoNorge, then open it and plot it:
fylker <- st_read("data/fylker2021.json")
ggplot(fylker) +
geom_sf()
#see all packages etc. I need to load. Such as library(sf) etc. THEN
##You can find the coordinate system of a sf class object with sf::st_crs().
```
```{r}
#trying to get Nordhordland BR border into the Norway map:
library(sf)
NBR <- st_read("data/Cusens_data/nbr")
NBR
Alver <- st_read("data/Cusens_data/Alver_shapefiles")
Alver
#I opened them finally. Now try to plot them on a Norway map...?
#from Datalab 5: #23.1.3 other vector files
fylker <- st_read("data/fylker2021.json")
ggplot(fylker) +
geom_sf()
ggplot() +
geom_sf(data = fylker) +
geom_sf(data = NBR, fill = "lightblue") +
geom_sf(data = Alver)
#it worked except that I need Alver to show up also. I think the problem is that the Alver shapefile has a lot of data in it, so it doesn't know what I want to show (just the shape)
```
```{r}
#earlier stuff I did:
###Chapter 11###
#but using my data
#to import shapefiles use this package:
#install.packages("sf")
library(sf)
#install.packages("tidyverse")
library(tidyverse)
#install.packages("here")
library(here)
#location in this R project of Cusens data:
"Cusens_data/Cusens PPGIS data 2021"
PPGIS <- read_csv(file = here("Cusens_data/Cusens PPGIS data 2021/PPGIS_socio_demo_data.csv"))
spec(PPGIS)
problems(PPGIS)
head(PPGIS)
```
```{r}
#trying to open a gpkg file
#code for opening a GPKG file in a Rstudio project directory: first need some packages:
#install.packages(c("rgdal", "RSQLite"))
library(rgdal)
library(RSQLite)
#location in this R project of PPGIS data:
"Cusens_data/Cusens PPGIS data 2021/ppgis_point_data.gpkg"
# Explore the layers available
ogrListLayers("Cusens_data/Cusens PPGIS data 2021/ppgis_point_data.gpkg")
#Fixed opening the file because the wd was wrong (I missed the second folder)
#I want to open "ppgis_point"
dta <- src_sqlite("Cusens_data/Cusens PPGIS data 2021/ppgis_point_data.gpkg")
tbldata <- tbl(dta, "ppgis_point") # Replace "YourLayer" with the name of your layer
tbldf <- as.data.frame(tbldata)
tbldf
#now I need to learn how to manipulate the layer slash ppgis data I just opened...!
save.image()
```
```{r}
#Sept 26, 2023
#Need to use Datalab 5 to try some stuff here
```