postGIStools: Tools for Interacting with 'PostgreSQL' / 'PostGIS' Databases

> library(postGIStools)

バージョン: 0.2.1


関数名 概略
%->% Extract or replace hstore values by key
get_postgis_query Send SELECT query and parse geometry, hstore columns
new_hstore Create a empty hstore
postGIStools-package postGIStools: Tools for interacting with PostgreSQL / PostGIS Databases
postgis_insert Insert or update records in a PostgreSQL table from a R data frame.

get_postgis_query

> library(RPostgreSQL)
> con <- dbConnect(PostgreSQL(), dbname = "my_db")
> 
> # If geom column holds points, returns a SpatialPointsDataFrame
> cities <- get_postgis_query(con, "SELECT name, geom, datalist FROM city",
+                             geom_name = "geom", hstore_name = "datalist")
> 
> # Get the populations (part of datalist hstore) as a vector
> pop <- cities@data$datalist %->% "population"

new_hstore

> contacts <- data.frame(name = c("Anne", "Bert", "Chris"))
> contacts$phone <- new_hstore(3) # NULL
> contacts$phone %->% "home" <- c("555-123-4567", "555-923-9134", "555-276-1123")
> contacts$phone[2] %->% "cell" <- "555-889-9134"
> str(contacts)
'data.frame':    3 obs. of  2 variables:
 $ name : Factor w/ 3 levels "Anne","Bert",..: 1 2 3
 $ phone:List of 3
  ..$ :List of 1
  .. ..$ home: chr "555-123-4567"
  ..$ :List of 2
  .. ..$ home: chr "555-923-9134"
  .. ..$ cell: chr "555-889-9134"
  ..$ :List of 1
  .. ..$ home: chr "555-276-1123"

postgis_insert