ingec13

Usluge zasnovane na lokaciji - LV6

Oct 26th, 2021
994
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rm(list=ls())
  2. #!!! vAŽNO!!!Prije izvedbe p=ma, OBAVEZNO instalirati
  3. # sljedede dodatne Knjižnice:
  4. # leaflet, sp, sf, raster, mapview, rgdal
  5. #Položaji točaka
  6. #Koordinate mjesta dobiveneppm1211 alata:
  7. # https://www.mapdevelopers.com/geocode_tool.php
  8. name <- LETTERS[1:10]
  9. # imena tocaka
  10. longitude <- c(14.4258566, 14.3029538, 14.688725, 14.7607367, 14.4087218, 14.4636243, 14.8020393, 14.631247, 14.5395314, 14.7508013)
  11. latitude <- c(45.337594, 45.332782, 45.1740698, 44.7562894, 44.9604914, 44.5380381, 45.3991761, 45.0195884, 45.1588133, 44.9709329)
  12. #Geografske sirine i geografske duzine kao koordinate tocaka
  13. #u podatkovnom okviru 'stations'
  14. stations <- as.data.frame(cbind(longitude, latitude))
  15. # simulacije Kolicina padavina po tockama
  16. set.seed(0)
  17. precip <- round((runif(length(latitude))*10)^3)
  18. psize <- 1 + precip/500
  19. plot(stations, cex=psize, pch=20, col='red', main='Padavine')
  20. # Dodavanje imena stanicama text(stations, name, pos=4)
  21. # Dodavanje legende
  22. breaks <- c(100, 250, 500, 1000)
  23. legend.psize <- 1+breaks/500
  24. legend("topright", legend=breaks, pch=20, pt.cex=legend.psize, col='red', bg='gray')
  25.  
  26. # crtanje linija
  27. plot(stations, main='Precipitation')
  28. polygon(stations, col='blue', border='light blue')
  29. lines(stations, lwd=3, col='red')
  30. points(stations, cex=2, pch=20)
  31. points(stations, cex=psize, pch=20, col='red', main='Padavine')
  32. # Prikaz podataka na podlozi ogenstreetMap (OSM)
  33. library(leaflet)
  34. map.point <- leaflet() %>%
  35.   addTiles() %>%
  36.   # use the default base map which is openStreetMap tiles
  37.   addMarkers(lng=stations$longitude, lat=stations$latitude)
  38. map.point
  39. # MEĐUTIM, navedenipc.:~1 ip„§ uldiejs nisuREgs.,Wni!
  40. # Kao takvi nisu niti definirani u R-u!
  41.  
  42.  
  43. #Kreiranje i prikaz prostornih podataka
  44. library(sp)
  45. # Dodatne R knjiznice 'sp', 'raster', and 'rgdal' su osnova za rad s
  46. # prostornim podatcima!
  47. pts <- SpatialPoints(stations) # stations -> spatialPoints
  48.  
  49. # spatialPoiwts provjera
  50. class (pts)
  51. showDefault(pts)
  52.  
  53. #Defirricija referentnog kooridnatnog sustava
  54. crdref <- CRS('+proj=longlat +datum.WGS84')
  55. #spatial_Points s referentnim koordi_natnim sustavom
  56. pts <- SpatialPoints(stations, proj4string=crdref)
  57.  
  58. # slučajna opažanja kiše (simulacija)
  59. precipvalue <- runif(nrow(stations), min=0, max=100)
  60. df <- data.frame(ID=1:nrow(stations), precip=precipvalue)
  61. ptsdf <- SpatialPointsDataFrame(pts, data=df) # kise dodana u
  62.  
  63. print(ptsdf) # Provjera podatkovnog okvira
  64. plot(ptsdf) #Graficki prikaz tocaka
  65.  
  66.  
  67. # SpatialPoints in R
  68. longitude <- c(-116.7, -120.4, -116.7, -113.5, -115.5, -120.8, -119.5, -113.7, -113.7, 110.7)
  69. latitude <- c(45.3, 42.6, 38.9, 42.1, 35.7, 38.9, 36.2, 39, 41.6, 36.9)
  70. lonlat <- cbind(longitude, latitude)
  71.  
  72. library(sp)
  73. # 'sp', 'raster', and 'rgdal' are the essential additional R libraries # that manage spatial data!
  74. pts <- SpatialPoints(lonlat) # lonlat -> SpatialPoints
  75.  
  76. # spatialPoints examination
  77. class (pts)
  78. showDefault(pts)
  79.  
  80. crdref <- CRS('+proj=longlat +datum=WGS84') #defines the reference co-or
  81. pts <- SpatialPoints(lonlat, proj4string=crdref) #SpatialPoints with co-
  82.  
  83. # Random precipitation observations
  84. precipvalue <- runif(nrow(lonlat), min=0, max=100)
  85. df <- data.frame(ID=1:nrow(lonlat), precip=precipvalue)
  86. ptsdf <- SpatialPointsDataFrame(pts, data=df) # Precip. assigned to spat
  87.  
  88. print(ptsdf) # Inspection of spatial point data frame
  89. library(leaflet)
  90. map.point <- leaflet() %>%
  91.   addTiles() %>% # Koristena osnovna OSM podloga
  92.   addPolylines(lng=stations$longitude, lat=stations$latitude)
  93. map.point
  94. library(raster)
  95. #spatialLines and spatialPolygons
  96. lon <- c(-116.8, -114.2, -112.9, -111.9, -114.2, -115.4, -117.7)
  97. lat <- c(41.3, 42.9, 42.4, 39.8, 37.6, 38.3, 37.6)
  98. lonlat <- cbind(lon, lat)
  99. lns <- spLines(lonlat, crs=crdref)
  100. print(lns)
  101.  
  102. pols <- spPolygons(lonlat, crs=crdref)
  103. print(pols)
  104.  
  105. plot(pols, axes=TRUE, las=1)
  106. plot(pols, border='blue', col='yellow', lwd=3, add=TRUE)
  107. points(pts, col='red', pch=20, cex=3)
  108.  
  109. library(leaflet)
  110. map.poly <- leaflet() %>%
  111.   addTiles() %>% # use the default base map which is OpenStreetMap
  112.   addPolygons(lng=lon, lat=lat)
  113. map.poly
  114.  
  115. rm(list=ls())
  116. library(raster)
  117. r <- raster(ncol=10, nrow=10, xmx=-80, xmn=-150, ymn=20, ymx=60)
  118.  
  119. values(r) <- runif(ncell(r))
  120. print(r)
  121. values(r) <- 1:ncell(r)
  122. plot(r)
  123. lon <- c(-116.8, -114.2, -112.9, -111.9, -114.2, -115.4, -117.7)
  124. lat <- c(41.3, 42.9, 42.4, 39.8, 37.6, 38.3, 37.6)
  125. lonlat <- cbind(lon, lat)
  126. pols <- spPolygons(lonlat, crs='+proj=longlat +datum=WGS84')
  127. points(lonlat, col='red', pch=20, cex=3)
  128. plot(pols, border='blue', lwd=2, add=TRUE)
  129. library(raster)
  130. filename <- system.file("external/lux.shp", package="raster")
  131. print(filename)
  132.  
  133. s <- shapefile(filename)
  134. print(s)
  135. plot(s)
  136.  
  137. f <- system.file("external/rlogo.grd", package="raster")
  138. print(f)
  139.  
  140. r1 <- raster(f)
  141. print(r1)
  142. plot(r1)
  143. r2 <- raster(f, band=2)
  144. print(r2)
  145. plot(r2)
  146.  
  147. b <- brick(f)
  148. plot(b)
  149. s <- stack(f)
  150. plot(s)
  151.  
  152. #Postavljanje referentnog koordinatnog sustava i proiekcije
  153. library(rgdal)
  154. epsg <- make_EPSG()
  155. i <- grep("France", epsg$note, ignore.case=TRUE) # first three
  156. epsg[i[1:3], ]
  157. library(raster)
  158. library(rgdal)
  159. f <- system.file("external/lux.shp", package="raster")
  160. p <- shapefile(f)
  161. print(p)
  162. plot(p)
  163. #proyiera referentnog koordinatnog sustava, ako je nepoznat
  164.  
  165. #Kreiranje vlastite SHP baze
  166. #Postaviti setwd() na mapu ukojoj se nalazi datoteka 'polozaji.csv
  167. setwd('C:/Users/Krepana Krava/Documents/Faks/lokacije/kod')
  168.  
  169. #Položaji točaka
  170. stations <- read.csv('polozaji_HR.csv', header = FALSE, sep =',')
  171. colnames(stations) <- c('latitude', 'longitude')
  172. #Geografske širine i geografske dužine kao
  173. #koordinate točaka
  174. #u podatkovnom okviru stations
  175.  
  176. # Prikaz podataka na podlozi openstreetMap (osm)
  177. library(leaflet)
  178. map.point <- leaflet() %>%
  179.   addTiles() %>% # use the default base
  180.   #map which is openstreetmap tiles
  181.   addMarkers(lng=stations$longitude, lat=stations$latitude)
  182. map.point
  183. crdref <- CRS('+proj=longlat +datum=WGS84')
  184. #spatialPoints s referntnim koordinatnim sustavom
  185. pts <- SpatialPoints(stations, proj4string=crdref)
  186. # slučajna opazanja kiše (simulacija)
  187. precipvalue <- runif(nrow(stations), min=0, max=100)
  188. df <- data.frame(ID=1:nrow(stations), precip=precipvalue)
  189. ptsdf <- SpatialPointsDataFrame(pts, data=df) # Kol. kišel
  190. #dodana u podatkovni okvir
  191. print(ptsdf) # Provjera podatkovnog okvira
  192. plot(ptsdf) #Grafički prikaz točaka
  193.  
  194. library(leaflet)
  195. map.point <- leaflet() %>%
  196.   addCircleMarkers(lng=stations$longitude, lat=stations$latitude)%>%
  197.   addTiles() %>% # Korištena osnovna
  198.   #05Mpp41~
  199.   addPolylines(lng=stations$longitude, lat=stations$latitude)
  200. map.point
  201.  
  202. library(leaflet)
  203. map.point <- leaflet() %>%
  204.   addTiles() %>% # Korištena osnovna
  205.   #osm podloga
  206.   addPolylines(lng=stations$longitude, lat=stations$latitude)
  207. map.point
  208.  
RAW Paste Data