Difference between revisions of "Opasnet map"

From Testiwiki
Jump to: navigation, search
(organised and links added)
(Static GoogleMaps test: function reorganised)
Line 222: Line 222:
 
library(OpasnetUtilsExt)
 
library(OpasnetUtilsExt)
  
shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house')
+
shp <- readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house')
plotvar<-shp@data$ika
+
#oprint(shp@data[1:100 , ])
nclr<-8
+
 
plotclr<-brewer.pal(nclr,"Spectral")
+
plotvar <- shp@data$ika
class<-classIntervals(plotvar,nclr,style="quantile")
+
nclr <- 8
colcode<-findColours(class,plotclr)
 
  
 
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
proj4string(shp)<-("+init=epsg:3067")
+
proj4string(shp) <- ("+init=epsg:3067")
shp2<-spTransform(shp,epsg4326String)
+
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);
+
# MyMap function without the "file destination" parameter
 +
# Requires RgoogleMaps package
 +
 
 +
MyRmap <- function (
 +
shp2, # a spatial data object
 +
# lonR, # longitude of data points
 +
# latR, # latitude of data points
 +
center, # center of the map
 +
size = c(640, 480), # size of the map. This produces the right dimensions in Opasnet.
 +
MINIMUMSIZE = FALSE,
 +
RETURNIMAGE = TRUE,
 +
GRAYSCALE = FALSE,
 +
NEWMAP = TRUE,
 +
zoom,
 +
verbose = 1,
 +
pch = 19,
 +
cex = 0.3,
 +
legend_title = "",
 +
...
 +
) {
 +
plotclr <- brewer.pal(nclr,"Spectral")
 +
class <- classIntervals(plotvar,nclr,style="quantile")
 +
colcode <- findColours(class,plotclr)
 +
 
 +
latR <- shp2@coords[ , 2]
 +
lonR <- shp2@coords[ , 1]
 +
 
 +
mymarkers <- data.frame(
 +
lat = c(shp2@coords[,2]),
 +
lon = c(shp2@coords[,1]),
 +
color = colcode
 +
)
 +
 
 +
#get the bounding box:
  
#get the bounding box:
+
bb <- qbbox(lat = mymarkers[,"lat"], lon = mymarkers[,"lon"])
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))  
 
     if (missing(zoom))  
 
         zoom <- min(MaxZoom(latR, lonR, size))
 
         zoom <- min(MaxZoom(latR, lonR, size))
Line 276: Line 302:
 
             cat("new size: ", size, "\n")
 
             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")
+
MyMap <- GetMap(
 +
center = c(lat.center, lon.center),
 +
zoom = zoom,
 +
size = size,
 +
RETURNIMAGE = RETURNIMAGE,  
 +
GRAYSCALE = GRAYSCALE,  
 +
verbose = verbose,
 +
...
 +
)
 +
 
 +
PlotOnStaticMap(MyMap)
 +
 
 +
PlotOnStaticMap(
 +
MyMap,
 +
lat = mymarkers[,"lat"],
 +
lon = mymarkers[,"lon"],
 +
pch = pch,
 +
cex = cex,
 +
col = colcode,
 +
add = T
 +
)
  
PlotOnStaticMap(MyMap)
+
legend(
 +
"topleft",
 +
legend = names(attr(colcode, "table")),
 +
title = legend_title,
 +
fill = attr(colcode, "palette"),
 +
cex = 1.0,
 +
bty = "y",
 +
bg = "white"
 +
)
 +
}
  
PlotOnStaticMap(MyMap,lat=mymarkers[,"lat"],lon=mymarkers[,"lon"],pch=19,cex=0.3,col=colcode,add=T)
+
temp <- MyRmap(shp2, maptype = "mobile", legend_title = "Ikä") # bb$lonR, bb$latR
  
legend("topleft", legend=names(attr(colcode, "table")),title="Ika", fill=attr(colcode, "palette"),  cex=1.0, bty="y",bg="white")
 
 
</rcode>
 
</rcode>
  

Revision as of 13:25, 23 December 2013



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

+ Show code


GoogleMaps Sorvi MML TEST

#: Something wrong with sorvi. --Jouni (talk) 12:54, 23 December 2013 (EET)

+ Show code

Google with shapefiles

+ Show code

Google show data from url on map

+ Show code

Google circles

+ Show code

Static GoogleMaps test

+ Show code

See also

Keywords

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>