Question
How should GIS data be handled and visualised in Opasnet?
Answer
- Original GIS data is stored in a PostgreSQL database.
- Data is accessed by R using the RGDAL package and ?? connection.
- Data in manipulated in R.
- Ovariables are converted to SpatialPointsDataFrame objects using ova2spat function.
- Data is displayed by producing a KML file with ?? package.
- The KML file is created with MyPointKML function, if pins are shown.
- The KML file is saved at the R-tools server.
- Google Maps is used to show the KML file on a web page.
Currently, ova2spat and MyPointKML functions are located in OpasnetUtils/Drafts. Therefore, you need this command:
objects.latest("Op_en6007", code_name = "answer") # OpasnetUtils/Drafts. We need MyPointsKML and ova2spat.
This is the projection that the National Land Survey Finland uses: [1].
Key guidance:
Rationale
All pieces of the puzzle exist already.
Dependencies
Calculations
Kuopio buildings with Google pin map
GoogleMaps Sorvi MML TEST
⇤#: Something wrong with sorvi. --Jouni (talk) 12:54, 23 December 2013 (EET)
Google with shapefiles
Google show data from url on map
Google circles
Static GoogleMaps test
+ Show code- Hide code
library(RgoogleMaps)
library(rgdal)
library(maptools)
library(RColorBrewer)
library(classInt)
library(OpasnetUtils)
library(OpasnetUtilsExt)
shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house')
plotvar<-shp@data$ika
nclr<-8
plotclr<-brewer.pal(nclr,"Spectral")
class<-classIntervals(plotvar,nclr,style="quantile")
colcode<-findColours(class,plotclr)
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
proj4string(shp)<-("+init=epsg:3067")
shp2<-spTransform(shp,epsg4326String)
#get marker information first 10 points
mymarkers<-cbind.data.frame(lat=c(shp2@coords[,2]),lon=c(shp2@coords[,1]),color=colcode);
#get the bounding box:
bb <- qbbox(lat = mymarkers[,"lat"], lon = mymarkers[,"lon"])
#MyMap function without the "file destination" parameter
MyRmap<-function (lonR, latR, center, size = c(640, 640),
MINIMUMSIZE = FALSE, RETURNIMAGE = TRUE, GRAYSCALE = FALSE,
NEWMAP = TRUE, zoom, verbose = 1, ...)
{
if (missing(zoom))
zoom <- min(MaxZoom(latR, lonR, size))
if (missing(center)) {
lat.center <- mean(latR)
lon.center <- mean(lonR)
}
else {
lat.center <- center[1]
lon.center <- center[2]
}
if (MINIMUMSIZE) {
ll <- LatLon2XY(latR[1], lonR[1], zoom)
ur <- LatLon2XY(latR[2], lonR[2], zoom)
cr <- LatLon2XY(lat.center, lon.center, zoom)
ll.Rcoords <- Tile2R(ll, cr)
ur.Rcoords <- Tile2R(ur, cr)
if (verbose > 1) {
cat("ll:")
print(ll)
print(ll.Rcoords)
cat("ur:")
print(ur)
print(ur.Rcoords)
cat("cr:")
print(cr)
}
size[1] <- 2 * max(c(ceiling(abs(ll.Rcoords$X)), ceiling(abs(ur.Rcoords$X)))) +
1
size[2] <- 2 * max(c(ceiling(abs(ll.Rcoords$Y)), ceiling(abs(ur.Rcoords$Y)))) +
1
if (verbose)
cat("new size: ", size, "\n")
}
return(GetMap(center = c(lat.center, lon.center), zoom = zoom,
size = size, RETURNIMAGE = RETURNIMAGE,
GRAYSCALE = GRAYSCALE, verbose = verbose, ...))
}
MyMap<-MyRmap(bb$lonR,bb$latR,maptype="mobile")
PlotOnStaticMap(MyMap)
PlotOnStaticMap(MyMap,lat=mymarkers[,"lat"],lon=mymarkers[,"lon"],pch=19,cex=0.3,col=colcode,add=T)
legend("topleft", legend=names(attr(colcode, "table")),title="Ika", fill=attr(colcode, "palette"), cex=1.0, bty="y",bg="white")
| |
See also
Keywords
References
Related files
<mfanonymousfilelist></mfanonymousfilelist>