Wikisym 2012 Demo: Difference between revisions

From Opasnet
Jump to navigation Jump to search
Line 41: Line 41:
library(RColorBrewer)
library(RColorBrewer)
library(classInt)
library(classInt)
library(OpasnetBaseUtils)
library(OpasnetUtils)
library(OpasnetUtilsExt)
library(RODBC)
library(RODBC)


Line 70: Line 71:
description <- paste("<b>Age:</b>",shp2$ika,"<br><b>Building ID:</b>",shp2$rakennustunnus)
description <- paste("<b>Age:</b>",shp2$ika,"<br><b>Building ID:</b>",shp2$rakennustunnus)


MyPointKML<-function(obj = NULL, kmlname = "", kmldescription = "", name = NULL, description = "", icon = "http://maps.google.com/mapfiles/kml/pal4/icon24.png",col=NULL)
data <- google.point_kml(shp2,kmlname,kmldescription,name,description,icon,colcode)
{
    if (is.null(obj))
        return(list(header = c("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
            "<kml xmlns=\"http://earth.google.com/kml/2.2\">",
            "<Document>", paste("<name>", kmlname, "</name>",
                sep = ""), paste("<description><![CDATA[", kmldescription,
                "]]></description>", sep = "")), footer = c("</Document>",
            "</kml>")))
    if (class(obj) != "SpatialPointsDataFrame")
        stop("obj must be of class 'SpatialPointsDataFrame' [package 'sp']")
    if (is.null(name)) {
        name = c()
        for (i in 1:nrow(obj)) name <- append(name, paste("site",
            i))
    }
 
    col2kmlcolor <- function(col) paste(rev(sapply(col2rgb(col, TRUE), function(x) sprintf("%02x", x))), collapse = "")
    kml <- kmlStyle <- ""
    kmlHeader <- c("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","<kml xmlns=\"http://earth.google.com/kml/2.2\">", "<Document>")
    kmlFooter <- c("</Document>", "</kml>")
    for (i in 1:nrow(obj)) {
        point <- obj[i, ]
        pt_name = name[i]
        pt_description = description[i]
        pt_style <- paste("#style", ifelse(length(icon) == 1, 1, i), sep = "")
        kml <- append(kml, "<Placemark>")
        kml <- append(kml, paste("  <description><![CDATA[",pt_description, "]]></description>", sep = ""))
#kml <- append(kml, "<Style><IconStyle>")
#kml <- append(kml, paste("<color>", col2kmlcolor(col[i]), "</color>", sep =""))
        #kml <- append(kml, paste("  <Icon><href>", icon, "</href></Icon>", sep = ""))
#kml <- append(kml, "<scale>0.300000</scale>")
#kml <- append(kml, "</IconStyle></Style>")
        kml <- append(kml, "  <Point>")
        kml <- append(kml, "    <coordinates>")
        kml <- append(kml, paste(point@coords[1], point@coords[2], sep = ","))
        kml <- append(kml, "    </coordinates>")
        kml <- append(kml, "  </Point>")
        kml <- append(kml, "</Placemark>")
    }
   
    return(paste(paste(c(kmlHeader, kmlStyle, kml, kmlFooter), sep = "", collapse = "\n"), collapse="\n", sep = ""))
   
}
 
 
 
data <- MyPointKML(shp2,kmlname,kmldescription,name,description,icon,colcode)
google.show_kml_data_on_maps(data)
google.show_kml_data_on_maps(data)



Revision as of 12:36, 21 August 2012

Polygons on dynamic Google Maps

This example plots municipalities of Finland on Google Maps using data from National Land Survey of Finland.

+ Show code


Points on dynamic Google Maps

This examples plots buildings of Kuopio on Google Maps. User can give the minimum age of buildings to plot as an input parameter.


Building minimum age:

+ Show code

Large quantity of points on a static Google Maps

This example plots large number of point data on static Google Maps. The map produced in this example shows the age (in years) distribution of properites within Kuopio. User can select the number of age classes (4,6 or 8) and the type of classification.

Number of classes:

Type of classification:

+ Show code