Created
December 2, 2016 19:27
-
-
Save mhweber/09cd7e3248bbff8cea99b013ce0fe1c7 to your computer and use it in GitHub Desktop.
Figured out reading my PostGIS data directly in R using Rpostgis package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # example of reading regular data table from Postgres using RPostgresSQL library | |
| library(RPostgreSQL) | |
| con <- dbConnect(PostgreSQL(), host="localhost", port="5432", user="username", password="password", dbname="db_name") | |
| result <- dbGetQuery(con, statement = "SELECT * FROM table1, table2 WHERE table1.key = table2.key") | |
| head(result) | |
| # example of reading spatial data from PostGIS using rpostgis library | |
| library(rpostgis) | |
| conn <- dbConnect(PostgreSQL(), host="localhost", port="5432", user="postgres", password="postgres", dbname="sp_db") | |
| dbSchema(conn, name = 'sp_db') | |
| dbTableInfo(conn, "sp_table") | |
| my_spdf<-pgGetGeom(conn, name="sp_table", geom = "wkb_geometry") | |
| head(my_spdf@data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment