I'm transforming data from OSGB36 (epsg:27700) to WGS84 (epsg:4326). I'm experiencing a data alignment problem. The transformation requires a 300 ft shift west of current position and I've tried many other codes but none of them place the data on OSM other than '4326'. It may be I've not correctly stated the crs. Any help most appreciated. Data is coming from a 'Postgres/Postgis' table.
library(shiny)
library(shinythemes)
library(rsconnect)
library(RPostgreSQL)
library(rpostgis)
library(sp)
library(rgdal)
library(leaflet)
library(leaflet.extras)
# Specify Driver
pg <- dbDriver("PostgreSQL")
# Connection Details
con <- dbConnect(pg, user ='######', password ="######", host = "######" , port = 5432, dbname="######")
# List all Tables in database (to test the connection)
dbListTables(con)
# Read the PostGIS table "np_owned_land" into a 'data.frame'
dbReadTable(con, "np_owned_land", schema = "land_management") %>% head(3)
# list the Fields in the table
dbListFields(con, "np_owned_land", schema = "land_management")
# Query the tables for each layer you require
query <- "SELECT * FROM np_owned_land"
np_owned_land <- pgGetGeom(con, c("land_management","np_owned_land"), geom = "wkb_geometry", gid = "ogc_fid", other.cols = TRUE)
query <- "SELECT * FROM land_ownership"
land_ownership <- pgGetGeom(con, c("land_management","land_ownership"), geom = "wkb_geometry", gid = "ogc_fid", other.cols = TRUE)
# Change the projection from OSGB36 (epsg:27700) to WGS 84 (epsg:4326)
np_owned_land <- spTransform(np_owned_land, CRS(SRS_string ="EPSG:4326"))
land_ownership <- spTransform(land_ownership, CRS(SRS_string ="EPSG:4326"))
ui <- fluidPage(theme = shinytheme("cerulean"),
tags$head(HTML("<title>Land Ownership</title> <link rel='icon'type='image/png' href='logo.png'>")),
titlePanel(title=div(img(src="BBNPA Logo_small_RGB_transparent.png", style = "padding:5px", height = 130, width = 95, align = "left","Land Ownership"))),
h4("The land does not include management agreements and other legal interests."),
p("The layers consist of owned land
![alignment|690x332](upload://izjUfuqMifGiv2HXeWmdZA8lpyy.png)
."),
leafletOutput("np_owned_land", height = 700))
# Server Function:
server <- function(input, output, session)
output$np_owned_land <- renderLeaflet ({
map <- leaflet(np_owned_land) %>%
setView(-3.4710, 51.8633, zoom = 10) %>%
addTiles(group="OpenStreetMap.Mapnik") %>%
addProviderTiles("Esri.WorldImagery", group = "Satellite") %>%
addProviderTiles("OpenStreetMap.HOT", group = "OpenStreetMap.HOT") %>%
addProviderTiles("Stamen.TerrainBackground", group = "Stamen.TerrainBackground") %>%
addMiniMap(tiles = "OpenStreetMap.HOT", toggleDisplay = TRUE) %>%
addSearchOSM() %>%
addEasyButton(easyButton(icon="fa-globe", title="Zoom to Level 1", onClick=JS("function(btn, map){ map.setZoom(1); }"))) %>%
addEasyButton(easyButton(icon="fa-crosshairs", title="Locate Me", onClick=JS("function(btn, map){ map.locate({setView: true}); }"))) %>%
addPolygons(data=np_owned_land,
fillColor = "#e41a1c",
fillOpacity = 0.4,
stroke = "#690E0E",
dashArray = "4",
weight = 0.7,
label = ~name_of_area,
labelOptions = labelOptions(style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "13px", direction = "auto"),
group = "np_owned_land",
highlight = highlightOptions(color = "black", weight = 4, bringToFront = TRUE)) %>%
addPolygons(data=land_ownership,
fillColor = "#377eb8",
fillOpacity = 0.4,
stroke = "#20445F",
dashArray = "4",
weight = 0.7,
label = ~owner,
labelOptions = labelOptions(style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "13px", direction = "auto"),
group = "land_ownership",
highlight = highlightOptions(color = "black", weight = 4, bringToFront = TRUE)) %>%
addLegend("bottomleft", title = "Map Legend", colors = c("#e41a1c","#377eb8"), labels = c("NP Owned Land","Land Ownership")) %>%
addFullscreenControl() %>%
addMeasure() %>%
addScaleBar(position = c("bottomleft")) %>%
addLayersControl(baseGroups = c("OpenStreetMap.Mapnik","Satellite","OpenStreetMap.HOT","Stamen.TerrainBackground"),
overlayGroups = c("np_owned_land","land_ownership"),
options = layersControlOptions(collapsed = TRUE))
map
})
# ShinyApp Function:
shinyApp(ui = ui, server = server)