|
|
@@ -1,512 +1,512 @@
|
|
|
-ls <- list.files(path = tmp_dir, pattern = ".txt")
|
|
|
-ls_long <- list.files(path = tmp_dir, pattern = ".txt", full.names = T)
|
|
|
-tbl_names <- tools::file_path_sans_ext(list.files(path = tmp_dir, pattern = "*.txt"))
|
|
|
-# Export to postgis
|
|
|
-if (is.null(conf)) {
|
|
|
-conf <- ruut::get_config()
|
|
|
-conf$schema <- "xgtfs"
|
|
|
-conf$table <- ""
|
|
|
-}
|
|
|
-conf$table <- 'shapes'
|
|
|
-ruut::db_create_new_schema(conf = conf)
|
|
|
-# Postgresql string
|
|
|
-pg <- ruut::construct_ogr2ogr_PG_connect_str()
|
|
|
-# Connect to db
|
|
|
-conn <- ruut::db_connect()
|
|
|
-pg
|
|
|
-tbl_names
|
|
|
-i=8
|
|
|
-conf$table <- tbl_names[i]
|
|
|
-conf
|
|
|
-system(sprintf("mv %s %s/%s.csv", ls_long[i], tmp_dir, tbl_names[i]))
|
|
|
-shapes <- utils::read.csv(file = sprintf("%s/%s.csv", tmp_dir, tbl_names[i]))
|
|
|
-## --------------- Points to SpatialLines -----------------
|
|
|
-cat("\n----------------\nMarsruutide geomeetria loomine\n")
|
|
|
-sl <- shapes %>%
|
|
|
-dplyr::arrange(shape_id, shape_pt_sequence) %>%
|
|
|
-sf::st_as_sf(coords = c("shape_pt_lon", "shape_pt_lat"), agr = "constant") %>%
|
|
|
-# dplyr::group_by(shape_id) %>%
|
|
|
-# dplyr::summarise() %>%
|
|
|
-sf::st_cast("POINT")
|
|
|
-sf::st_crs(sl) <- 4326
|
|
|
-sl <- shapes %>%
|
|
|
-dplyr::arrange(shape_id, shape_pt_sequence) %>%
|
|
|
-sf::st_as_sf(coords = c("shape_pt_lon", "shape_pt_lat"), agr = "constant") %>%
|
|
|
-# dplyr::group_by(shape_id) %>%
|
|
|
-# dplyr::summarise() %>%
|
|
|
-sf::st_cast("POINT")
|
|
|
-library(dplyr)
|
|
|
-sl <- shapes %>%
|
|
|
-dplyr::arrange(shape_id, shape_pt_sequence) %>%
|
|
|
-sf::st_as_sf(coords = c("shape_pt_lon", "shape_pt_lat"), agr = "constant") %>%
|
|
|
-# dplyr::group_by(shape_id) %>%
|
|
|
-# dplyr::summarise() %>%
|
|
|
-sf::st_cast("POINT")
|
|
|
-sf::st_crs(sl) <- 4326
|
|
|
-tabeli_suffix <- "_source"
|
|
|
-sf::st_write(
|
|
|
-obj = sl, dsn = conn, layer_options = c("GEOMETRY=AS_XY", "OVERWRITE=yes"),
|
|
|
-layer = sprintf("%s%s", conf$table, tabeli_suffix)
|
|
|
+geometry_type = "PROMOTE_TO_MULTI"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-# Change schema
|
|
|
-q <- sprintf("
|
|
|
-drop table if exists %s.%s%s cascade; \
|
|
|
-ALTER TABLE %s%s SET SCHEMA %s", conf$schema, conf$table, tabeli_suffix, conf$table, tabeli_suffix, conf$schema)
|
|
|
-cat("\n----------------\nMuudame schema.\n")
|
|
|
-cat(q)
|
|
|
-DBI::dbExecute(conn, q)
|
|
|
-output <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' table=\"%s\".\"%s\" (geom)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-input <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' srid=4326 type=Point checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s_source\" (geometry)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
)
|
|
|
-result <- qgisprocess::qgis_run_algorithm(
|
|
|
-algorithm = algorithm,
|
|
|
-CLOSE_PATH = 0,
|
|
|
-DATE_FORMAT = "",
|
|
|
-GROUP_FIELD = "shape_id",
|
|
|
-INPUT = input,
|
|
|
-ORDER_FIELD = "shape_pt_sequence",
|
|
|
-OUTPUT = output,
|
|
|
-.quiet = TRUE
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-# qgis_algorithm_search_by_word(str = "pointstopath")
|
|
|
-algorithm <- "qgis:pointstopath"
|
|
|
-# cat(qgis_show_help(algorithm = algorithm))
|
|
|
-# Run algorithm.
|
|
|
-## !!!!!!!!!!!!!!!!!!!! NB! pead muutma pythoni skripti 188 rida.
|
|
|
-## File "/usr/share/qgis/python/plugins/processing/algs/qgis/PointsToPaths.py", line 188, in processAlgorithm
|
|
|
-## Panin sinna mingi faili, sest temp faili ei osanud python kirjutada ja pärast lugeda.
|
|
|
-output <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' table=\"%s\".\"%s\" (geom)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+conf$dbname
|
|
|
+conf$host
|
|
|
+conf$port
|
|
|
+conf$user
|
|
|
+conf$password
|
|
|
+conf$sslmode
|
|
|
+conf$schema
|
|
|
+source
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+source
|
|
|
+source
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-input <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' srid=4326 type=Point checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s_source\" (geometry)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+conf$table
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+## Export to postgis database.
|
|
|
+conf$primary_key = 'id'
|
|
|
+conf$s_srs = "EPSG:3301"
|
|
|
+conf$t_srs = "EPSG:3301"
|
|
|
+geometry_type = "PROMOTE_TO_MULTI"
|
|
|
+# ruut::copy_shp_to_db(
|
|
|
+# dir = tmp_dir_kihid, layer = tbl_names[i], conf = conf,
|
|
|
+# id = "id", crs_source = "EPSG:3301", crs_target = "EPSG:3301",
|
|
|
+# geometry_type = "PROMOTE_TO_MULTI"
|
|
|
+# )
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING ISO-8859-4 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-result <- qgisprocess::qgis_run_algorithm(
|
|
|
-algorithm = algorithm,
|
|
|
-CLOSE_PATH = 0,
|
|
|
-DATE_FORMAT = "",
|
|
|
-GROUP_FIELD = "shape_id",
|
|
|
-INPUT = input,
|
|
|
-ORDER_FIELD = "shape_pt_sequence",
|
|
|
-OUTPUT = output,
|
|
|
-.quiet = TRUE
|
|
|
+system(cmd)
|
|
|
+cat(sprintf(
|
|
|
+"\nShp fail %s kopeeriti POSTGIS andmebaasi %s.%s\n\n",
|
|
|
+ls[i], conf$schema, conf$table
|
|
|
+))
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=ISO-8859-4; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING UTF-8 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=UTF-8; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING UTF-8 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
+system(cmd)
|
|
|
styler:::style_active_file()
|
|
|
-conf = NULL
|
|
|
-library(dplyr)
|
|
|
-# Temp directory
|
|
|
-tmp_dir <- "/tmp/gtfs"
|
|
|
-if (!dir.exists(tmp_dir)) {
|
|
|
-dir.create(tmp_dir)
|
|
|
-}
|
|
|
-# Download link
|
|
|
-url <- "http://www.peatus.ee/gtfs/"
|
|
|
-# Estonia shapefile (ZIP archive)
|
|
|
-map_shapefile <- "gtfs.zip"
|
|
|
-# Download and save
|
|
|
-url_download <- sprintf("%s%s", url, map_shapefile)
|
|
|
-saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
-if (!file.exists(saveTo)) {
|
|
|
-utils::download.file(
|
|
|
-url = url_download,
|
|
|
-destfile = saveTo, method = "curl", extra = "-L"
|
|
|
+library(estmap)
|
|
|
+encoding <- 'UTF-8'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-}
|
|
|
+cmd
|
|
|
+tbl_names
|
|
|
+i = 33
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+## Export to postgis database.
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+encoding <- 'UTF-8'
|
|
|
+encoding <- 'CP1257'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
# Unzip
|
|
|
utils::unzip(saveTo, overwrite = T, exdir = tmp_dir)
|
|
|
-# List of files
|
|
|
-ls <- list.files(path = tmp_dir, pattern = ".txt")
|
|
|
-ls_long <- list.files(path = tmp_dir, pattern = ".txt", full.names = T)
|
|
|
-tbl_names <- tools::file_path_sans_ext(list.files(path = tmp_dir, pattern = "*.txt"))
|
|
|
-# Export to postgis
|
|
|
-if (is.null(conf)) {
|
|
|
-conf <- ruut::get_config()
|
|
|
-conf$schema <- "gtfs"
|
|
|
-conf$table <- ""
|
|
|
-}
|
|
|
-# Multi layer: paneme kõik csv failid üheks failiks.
|
|
|
-if (file.exists(saveTo)) {
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
## Export to postgis database.
|
|
|
-# New schema
|
|
|
-ruut::db_create_new_schema(conf = conf)
|
|
|
-# Postgresql string
|
|
|
-pg <- ruut::construct_ogr2ogr_PG_connect_str()
|
|
|
-# Connect to db
|
|
|
-conn <- ruut::db_connect()
|
|
|
-# ---------- Copy CSV!!! data to database ----------
|
|
|
-for (i in 1:length(tbl_names)) {
|
|
|
-# Tabeli nimi
|
|
|
-conf$table <- tbl_names[i]
|
|
|
-# ogr2ogr oskab csv faili lugeda juhul kui laiend on csv. Muudame.
|
|
|
-system(sprintf("mv %s %s/%s.csv", ls_long[i], tmp_dir, tbl_names[i]))
|
|
|
-# Laeme eraldi andmed shape muutujasse, et teede geomeetriat leida
|
|
|
-if (tbl_names[i] == "shapes") {
|
|
|
-shapes <- utils::read.csv(file = sprintf("%s/%s.csv", tmp_dir, tbl_names[i]))
|
|
|
-## --------------- Points to SpatialLines -----------------
|
|
|
-cat("\n----------------\nMarsruutide geomeetria loomine\n")
|
|
|
-sl <- shapes %>%
|
|
|
-dplyr::arrange(shape_id, shape_pt_sequence) %>%
|
|
|
-sf::st_as_sf(coords = c("shape_pt_lon", "shape_pt_lat"), agr = "constant") %>%
|
|
|
-# dplyr::group_by(shape_id) %>%
|
|
|
-# dplyr::summarise() %>%
|
|
|
-sf::st_cast("POINT")
|
|
|
-sf::st_crs(sl) <- 4326
|
|
|
-# # Test plot
|
|
|
-# sl %>%
|
|
|
-# ggplot2::ggplot(ggplot2::aes(colour = shape_id)) +
|
|
|
-# ggplot2::geom_sf()
|
|
|
-# plot(sl)
|
|
|
-# Write to database
|
|
|
-tabeli_suffix <- "_source"
|
|
|
-sf::st_write(
|
|
|
-obj = sl, dsn = conn, layer_options = c("GEOMETRY=AS_XY", "OVERWRITE=yes"),
|
|
|
-layer = sprintf("%s%s", conf$table, tabeli_suffix)
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+encoding <- 'UTF-8'
|
|
|
+encoding <- 'CP1257'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-# Change schema
|
|
|
-q <- sprintf("
|
|
|
-drop table if exists %s.%s%s cascade; \
|
|
|
-ALTER TABLE %s%s SET SCHEMA %s", conf$schema, conf$table, tabeli_suffix, conf$table, tabeli_suffix, conf$schema)
|
|
|
-cat("\n----------------\nMuudame schema.\n")
|
|
|
-cat(q)
|
|
|
-DBI::dbExecute(conn, q)
|
|
|
-# ----------- Point to path teisendus ------------
|
|
|
-# Algoritmi juhend!
|
|
|
-# qgis_algorithm_search_by_word(str = "pointstopath")
|
|
|
-algorithm <- "qgis:pointstopath"
|
|
|
-# cat(qgis_show_help(algorithm = algorithm))
|
|
|
-# Run algorithm.
|
|
|
-## !!!!!!!!!!!!!!!!!!!! NB! pead muutma pythoni skripti 188 rida.
|
|
|
-## File "/usr/share/qgis/python/plugins/processing/algs/qgis/PointsToPaths.py", line 188, in processAlgorithm
|
|
|
-## Panin sinna mingi faili, sest temp faili ei osanud python kirjutada ja pärast lugeda.
|
|
|
-output <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' table=\"%s\".\"%s\" (geom)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+system(cmd)
|
|
|
+encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-input <- sprintf(
|
|
|
-'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' srid=4326 type=Point checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s_source\" (geometry)',
|
|
|
-conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
-conf$schema, conf$table
|
|
|
+system(cmd)
|
|
|
+encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-result <- qgisprocess::qgis_run_algorithm(
|
|
|
-algorithm = algorithm,
|
|
|
-CLOSE_PATH = 0,
|
|
|
-DATE_FORMAT = "",
|
|
|
-GROUP_FIELD = "shape_id",
|
|
|
-INPUT = input,
|
|
|
-ORDER_FIELD = "shape_pt_sequence",
|
|
|
-OUTPUT = output,
|
|
|
-.quiet = TRUE
|
|
|
+system(cmd)
|
|
|
+encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-} else {
|
|
|
+system(cmd)
|
|
|
+encoding <- 'UTF-8'
|
|
|
cmd <- sprintf(
|
|
|
paste0(
|
|
|
-"ogr2ogr -f PostgreSQL ",
|
|
|
-"%s -lco SCHEMA=%s -lco OVERWRITE=yes -lco FID=%s -nln \"%s\" \"%s/%s.csv\""
|
|
|
-), pg, conf$schema, "fid", conf$table, tmp_dir, tbl_names[i]
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-cat(cmd)
|
|
|
-cat("\n\n")
|
|
|
system(cmd)
|
|
|
-}
|
|
|
-}
|
|
|
-# Lisame andmebaasi seosed
|
|
|
-q <- sprintf("
|
|
|
-ALTER TABLE %s.agency ADD CONSTRAINT agency_un UNIQUE (agency_id); \
|
|
|
-ALTER TABLE %s.calendar ADD CONSTRAINT calendar_un UNIQUE (service_id); \
|
|
|
-ALTER TABLE %s.fare_attributes ADD CONSTRAINT fare_attributes_un UNIQUE (fare_id); \
|
|
|
-ALTER TABLE %s.routes ADD CONSTRAINT routes_un UNIQUE (route_id); \
|
|
|
-ALTER TABLE %s.shapes ADD CONSTRAINT shapes_un UNIQUE (shape_id); \
|
|
|
-ALTER TABLE %s.stops ADD CONSTRAINT stops_un UNIQUE (stop_id); \
|
|
|
-ALTER TABLE %s.trips ADD CONSTRAINT trips_un UNIQUE (trip_id); \
|
|
|
-ALTER TABLE %s.fare_rules ADD CONSTRAINT fare_rules_fk FOREIGN KEY (fare_id) REFERENCES %s.fare_attributes(fare_id); \
|
|
|
-ALTER TABLE %s.fare_attributes ADD CONSTRAINT fare_attributes_fk FOREIGN KEY (agency_id) REFERENCES %s.agency(agency_id); \
|
|
|
-ALTER TABLE %s.routes ADD CONSTRAINT routes_fk FOREIGN KEY (agency_id) REFERENCES %s.agency(agency_id); \
|
|
|
-ALTER TABLE %s.calendar_dates ADD CONSTRAINT calendar_dates_fk FOREIGN KEY (service_id) REFERENCES %s.calendar(service_id); \
|
|
|
-ALTER TABLE %s.fare_rules ADD CONSTRAINT fare_rules_route_fk FOREIGN KEY (route_id) REFERENCES %s.routes(route_id); \
|
|
|
-ALTER TABLE %s.stop_times ADD CONSTRAINT stop_times_stops_fk FOREIGN KEY (stop_id) REFERENCES %s.stops(stop_id); \
|
|
|
-ALTER TABLE %s.stop_times ADD CONSTRAINT stop_times_trips_fk FOREIGN KEY (trip_id) REFERENCES %s.trips(trip_id); \
|
|
|
-ALTER TABLE %s.trips ADD CONSTRAINT trips_calendar_fk FOREIGN KEY (service_id) REFERENCES %s.calendar(service_id); \
|
|
|
-ALTER TABLE %s.trips ADD CONSTRAINT trips_routes_fk FOREIGN KEY (route_id) REFERENCES %s.routes(route_id);", conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema, conf$schema)
|
|
|
-cat(q)
|
|
|
-DBI::dbExecute(conn, q)
|
|
|
-# ogr2ogr help.
|
|
|
-# system("ogr2ogr --long-usage")
|
|
|
-# ogrinfo help.
|
|
|
-# system("ogrinfo --help-general")
|
|
|
-# pg <- ruut::construct_ogr2ogr_PG_connect_str()
|
|
|
-# system(sprintf("ogrinfo %s xgtfs.trips ", pg))
|
|
|
-# system(sprintf("ogrinfo %s xgtfs.trips ", pg))
|
|
|
-}
|
|
|
-# Delete temp directory
|
|
|
-# system(sprintf("rm -rf %s/*.csv", tmp_dir))
|
|
|
-}
|
|
|
-library(estmap)
|
|
|
-library(estmap)
|
|
|
-urls <- c("19-1.IBehaviorListener.2-=", "19-1.IBehaviorListener.2-")
|
|
|
-url_download <- "https://teeregister.mnt.ee/reet/shpreports?"
|
|
|
-url_download <- "https://teeregister.mnt.ee/reet/shpreports"
|
|
|
-urls <- c("19-1.IBehaviorListener.2-=", "19-1.IBehaviorListener.2-")
|
|
|
-i <- 1
|
|
|
-url <- sprintf("%s?%s", url_download, urls[i])
|
|
|
-cat(url)
|
|
|
-url_download <- "https://teeregister.mnt.ee/reet/shpreports"
|
|
|
-urls <- c("0-9.IBehaviorListener.0-RIIGITEE_SOIDUTEED", "19-1.IBehaviorListener.2-", "0-2.IBehaviorListener.2-")
|
|
|
-i <- 1
|
|
|
-url <- sprintf("%s?%s", url_download, urls[i])
|
|
|
-cat(url)
|
|
|
-url_download <- "https://teeregister.mnt.ee/reet/shpreports"
|
|
|
-urls <- c("0-5.IBehaviorListener.0-:idc", "19-1.IBehaviorListener.2-", "0-2.IBehaviorListener.2-")
|
|
|
-i <- 1
|
|
|
-url <- sprintf("%s?%s", url_download, urls[i])
|
|
|
-cat(url)
|
|
|
-system.file("inst/testimiseks/","test_1.R",package = "estmap")
|
|
|
-system.file("testimiseks/","test_1.R",package = "estmap")
|
|
|
-system.file("testimiseks","test_1.R",package = "estmap")
|
|
|
-library(estmap)
|
|
|
-tmp_dir <- system.file("tmp","gtfs",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-system.file("tmp","gtfs",package = "estmap")
|
|
|
-tmp_dir <- system.file("tmp","Untitled Document.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- system.file("tmp/gtfs","Untitled Document.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- system.file("gtfs","Untitled Document.txt",package = "estmap")
|
|
|
-tmp_dir <- system.file("tmp","gtfs/Untitled Document.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- system.file("tmp","Untitled.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- system.file("undelited","undelited.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- system.file("undelited","undelited.txt",package = "estmap")
|
|
|
-tmp_dir
|
|
|
-system.file("undelited","test_1.R",package = "estmap")
|
|
|
-system.file("undelited","undelited.txt",package = "estmap")
|
|
|
-system.file("undelited","Undelited.txt",package = "estmap")
|
|
|
-system.file("undelited","Undelited.txt",package = "estmap")
|
|
|
-system.file("untitled","test_1.R",package = "estmap")
|
|
|
-system.file("untitled","test_1.R",package = "estmap")
|
|
|
-system.file("untitled","test_1.R",package = "estmap")
|
|
|
-system.file("untitled","test_1.R",package = "estmap")
|
|
|
-library(estmap)
|
|
|
-system.file("undelited","Undelited.txt",package = "estmap")
|
|
|
-system.file("untitled","Undelited.txt",package = "estmap")
|
|
|
-system.file("untitled","Untitled.txt",package = "estmap")
|
|
|
-system.file("tmp","Untitled.txt",package = "estmap")
|
|
|
-system.file("tmp/gtfs","Untitled.txt",package = "estmap")
|
|
|
-system.file("tmp/gtfs","Untitled.txt",package = "estmap")
|
|
|
-system.file("DESCRIPTION",package = "estmap")
|
|
|
-system.file("DESCRIPTION",package = "estmap")
|
|
|
-system.file(package = "estmap")
|
|
|
-tmp_dir <- sprintf("%s", system.file(package = "estmap"))
|
|
|
-tmp_dir
|
|
|
-tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "gtfs")
|
|
|
-tmp_dir
|
|
|
-library(estmap)
|
|
|
-library(estmap)
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-if (!ans | is.na(ans)) {
|
|
|
-cat("\n------------------------\n")
|
|
|
-cat("Kaardikihte ei lisatud.")
|
|
|
-cat("\n------------------------\n")
|
|
|
-return()
|
|
|
-}
|
|
|
-!ans | is.na(ans)
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-!ans | is.na(ans)
|
|
|
-is.na(ans)
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-is.na(ans)
|
|
|
-!ans | is.na(ans)
|
|
|
-ans
|
|
|
-ans <- NA
|
|
|
-ans
|
|
|
-ans <- NA
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-cat("\n------------------------\n")
|
|
|
-cat("Kaardikihte ei lisatud.")
|
|
|
-cat("\n------------------------\n")
|
|
|
-return()
|
|
|
-}
|
|
|
-if (!ans | is.na(ans)) {
|
|
|
-cat("\n------------------------\n")
|
|
|
-cat("Kaardikihte ei lisatud.")
|
|
|
-cat("\n------------------------\n")
|
|
|
-return()
|
|
|
-}
|
|
|
-if (!ans | is.na(ans)) {
|
|
|
-cat("\n------------------------\n")
|
|
|
-cat("Kaardikihte ei lisatud.")
|
|
|
-cat("\n------------------------\n")
|
|
|
-# return()
|
|
|
-}
|
|
|
-ans <- NA
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-cat("\n------------------------\n")
|
|
|
-cat("Kaardikihte ei lisatud.")
|
|
|
-cat("\n------------------------\n")
|
|
|
-# return()
|
|
|
-}
|
|
|
-ans <- NA
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- NA
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?")
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?", default = F)
|
|
|
-ans
|
|
|
-ans <- utils::askYesNo("Do you want to import gtfs data into database?", default = F)
|
|
|
-ans
|
|
|
-styler:::style_active_file()
|
|
|
+tbl_names
|
|
|
+i=15
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+## Export to postgis database.
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+encoding <- 'UTF-8'
|
|
|
+# encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+tbl_names
|
|
|
+i = 41
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+## Export to postgis database.
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+encoding <- 'UTF-8'
|
|
|
+# encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+encoding <- 'UTF-16'
|
|
|
+# encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+encoding <- 'UTF-16'
|
|
|
+# encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+encoding <- 'ISO-8859-4'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+tbl_names[i]
|
|
|
+if(tbl_names[i] %in% c('Kirik_p')) encoding <- 'ISO-8859-4' else encoding <- 'UTF-8'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=%s; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s -skipfailures"
|
|
|
+), encoding, encoding,
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+styler:::style_selection()
|
|
|
styler:::style_active_file()
|
|
|
-library(estmap)
|
|
|
-library(estmap)
|
|
|
-library(estmap)
|
|
|
-conf = NULL
|
|
|
-# Temp directory
|
|
|
-tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "osm_shp")
|
|
|
-if (!dir.exists(tmp_dir)) {
|
|
|
-dir.create(tmp_dir)
|
|
|
-}
|
|
|
-# Download link
|
|
|
-url <- "https://download.geofabrik.de/europe"
|
|
|
+url <- "https://geoportaal.maaamet.ee/docs/muld"
|
|
|
# Estonia shapefile (ZIP archive)
|
|
|
-map_shapefile <- "estonia-latest-free.shp.zip"
|
|
|
+map_shapefile <- "Mullakaart_SHP.zip"
|
|
|
# Download and save
|
|
|
-url_download <- sprintf("%s/%s", url, map_shapefile)
|
|
|
+url_download <- sprintf("%s", url)
|
|
|
saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
-if (!file.exists(saveTo)) {
|
|
|
-utils::download.file(
|
|
|
-url = url_download,
|
|
|
-destfile = saveTo, method = "curl", extra = "-L"
|
|
|
-)
|
|
|
-}
|
|
|
-# Unzip
|
|
|
-utils::unzip(saveTo, overwrite = T, exdir = tmp_dir)
|
|
|
-# List of files
|
|
|
-ls <- list.files(path = tmp_dir, pattern = ".dbf")
|
|
|
-ls_long <- list.files(path = tmp_dir, pattern = ".dbf", full.names = T)
|
|
|
-tbl_names <- unlist(strsplit(x = ls, split = ".dbf"))
|
|
|
-# Export to postgis
|
|
|
-if (is.null(conf)) {
|
|
|
-conf <- ruut::get_config()
|
|
|
-conf$schema <- "osm_shp"
|
|
|
-}
|
|
|
-# New schema
|
|
|
-ruut::db_create_new_schema(conf = conf)
|
|
|
-tbl_names
|
|
|
-conf = NULL
|
|
|
+url_download
|
|
|
+url <- "https://geoportaal.maaamet.ee/docs/muld/Mullakaart_SHP.zip"
|
|
|
+# Estonia shapefile (ZIP archive)
|
|
|
+map_shapefile <- "Mullakaart_SHP.zip"
|
|
|
+# Download and save
|
|
|
+url_download <- sprintf("%s", url)
|
|
|
+url_download
|
|
|
+saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
+saveTo
|
|
|
# Temp directory
|
|
|
-tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "osm_shp")
|
|
|
+tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "maaamet_mullakaart")
|
|
|
if (!dir.exists(tmp_dir)) {
|
|
|
dir.create(tmp_dir)
|
|
|
}
|
|
|
# Download link
|
|
|
-url <- "https://download.geofabrik.de/europe"
|
|
|
+url <- "https://geoportaal.maaamet.ee/docs/muld/Mullakaart_SHP.zip"
|
|
|
# Estonia shapefile (ZIP archive)
|
|
|
-map_shapefile <- "estonia-latest-free.shp.zip"
|
|
|
+map_shapefile <- "Mullakaart_SHP.zip"
|
|
|
# Download and save
|
|
|
-url_download <- sprintf("%s/%s", url, map_shapefile)
|
|
|
+url_download <- sprintf("%s", url)
|
|
|
saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
+saveTo
|
|
|
file.exists(saveTo)
|
|
|
-if (!file.exists(saveTo)) {
|
|
|
-utils::download.file(
|
|
|
-url = url_download,
|
|
|
-destfile = saveTo, method = "curl", extra = "-L"
|
|
|
-)
|
|
|
-}
|
|
|
# Unzip
|
|
|
utils::unzip(saveTo, overwrite = T, exdir = tmp_dir)
|
|
|
# List of files
|
|
|
+tmp_dir_kihid <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
+ls <- list.files(path = tmp_dir_kihid, pattern = ".dbf")
|
|
|
+ls_long <- list.files(path = tmp_dir_kihid, pattern = ".dbf", full.names = T)
|
|
|
+tbl_names <- unlist(strsplit(x = ls, split = ".dbf"))
|
|
|
+tbl_names
|
|
|
+ls
|
|
|
+tmp_dir
|
|
|
+tmp_dir
|
|
|
+ls <- list.files(path = tmp_dir, pattern = ".dbf")
|
|
|
+ls
|
|
|
ls <- list.files(path = tmp_dir, pattern = ".dbf")
|
|
|
ls_long <- list.files(path = tmp_dir, pattern = ".dbf", full.names = T)
|
|
|
tbl_names <- unlist(strsplit(x = ls, split = ".dbf"))
|
|
|
-# Export to postgis
|
|
|
-if (is.null(conf)) {
|
|
|
-conf <- ruut::get_config()
|
|
|
-conf$schema <- "osm_shp"
|
|
|
-}
|
|
|
-# New schema
|
|
|
+tbl_names
|
|
|
+conf$schema <- "eesti"
|
|
|
ruut::db_create_new_schema(conf = conf)
|
|
|
-map_shapefile
|
|
|
-# Multi layer
|
|
|
-for (i in 1:length(tbl_names)) {
|
|
|
+length(tbl_names)
|
|
|
+i=1
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+## Export to postgis database.
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=UTF-8; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING UTF-8 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+print(tbl_names[i])
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
|
|
|
+source
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=UTF-8; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING UTF-8 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+source
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
|
|
|
+source('~/apps/R/packages/estmap/R/maaamet_mullakaart.R', echo=TRUE)
|
|
|
+source
|
|
|
print(tbl_names[i])
|
|
|
-conf$table <- gsub("gis_osm_", "", gsub("_free_1", "", tbl_names[i]))
|
|
|
+conf$table <- tolower(tbl_names[i])
|
|
|
source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
|
|
|
## Export to postgis database.
|
|
|
-ruut::copy_shp_to_db(
|
|
|
-dir = tmp_dir, layer = tbl_names[i], conf = conf,
|
|
|
-id = "fid", crs_source = "EPSG:4326", crs_target = "EPSG:4326",
|
|
|
-geometry_type = "PROMOTE_TO_MULTI"
|
|
|
+conf$primary_key <- "id"
|
|
|
+conf$s_srs <- "EPSG:3301"
|
|
|
+conf$t_srs <- "EPSG:3301"
|
|
|
+geometry_type <- "PROMOTE_TO_MULTI"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"export PGCLIENTENCODING=UTF-8; ",
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING UTF-8 -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
|
|
|
+conf$s_srs, conf$t_srs, geometry_type
|
|
|
)
|
|
|
-cat(sprintf(
|
|
|
-"\nShp fail %s kopeeriti POSTGIS andmebaasi %s.%s\n\n",
|
|
|
-ls[i], conf$schema, conf$table
|
|
|
-))
|
|
|
-}
|
|
|
+system(cmd)
|
|
|
# Delete unnecessary files.
|
|
|
system(sprintf("find %s -type f -not -name '%s' -print0 | xargs -0 rm --", tmp_dir, map_shapefile))
|
|
|
styler:::style_active_file()
|
|
|
-styler:::style_active_file()
|
|
|
library(estmap)
|
|
|
-conf = NULL
|
|
|
-# Export to postgis
|
|
|
-if (is.null(conf)) {
|
|
|
-conf <- ruut::get_config()
|
|
|
-conf$schema <- "teeregister_wfs"
|
|
|
-}
|
|
|
-ruut::db_create_new_schema(conf = conf)
|
|
|
-## Teeregistri avaandmete kihtide lugemine
|
|
|
-wfs_list <- loe_teeregistri_wfs_kihid()
|
|
|
-layer_list <- wfs_list[, "layer"]
|
|
|
-wfs_list <- loe_teeregistri_wfs_kihid()
|
|
|
-wfs_list <- estmap:::loe_teeregistri_wfs_kihid()
|
|
|
-wfs_list
|
|
|
-layer_list
|
|
|
-layer_list <- wfs_list[, "layer"]
|
|
|
-layer_list
|
|
|
-installed_tables <- ruut::db_schema_tablenames(conf = conf)
|
|
|
-installed_tables
|
|
|
-layer_list
|
|
|
-i=1
|
|
|
-wfs_layer <- layer_list[i]
|
|
|
-conf$table <- gsub("ms:", "", wfs_layer)
|
|
|
-conf$table
|
|
|
-conf$table <- tolower(gsub("ms:", "", wfs_layer))
|
|
|
-conf$table
|
|
|
-conf$table %in% installed_tables
|
|
|
-!conf$table %in% installed_tables
|
|
|
+library(estmap)
|
|
|
styler:::style_active_file()
|
|
|
-i=58
|
|
|
-wfs_layer <- layer_list[i]
|
|
|
-conf$table <- tolower(gsub("ms:", "", wfs_layer))
|
|
|
-!conf$table %in% installed_tables
|
|
|
library(estmap)
|
|
|
-teeregister_wfs()
|
|
|
+library(estmap)
|
|
|
+library(estmap)
|
|
|
+library(estmap)
|
|
|
+library(estmap)
|