我不理解st_read
包中的sf
功能。
我尝试按照自己的postgisdata帮助中的示例进行操作。
**Connection to postgis:**
connz <- dbConnect(PostgreSQL(), dbname="gisdb", user = "postgres", password="postgres", host = "127.0.0.1")
**check tables in connection**
dbListTables(connz)
**Response**
*...
[41] "mijnlocatiesgoogle20171127" "vakantie"
[43] "vakantieactiviteiten" "uitmetbram"
...
所以有连接
**Get data using st_read**
xx = st_read(connz, "vakantie", query = "SELECT * FROM vakantie LIMIT 3;")
***Response**
xx = st_read(connz, "vakantie", query = "SELECT * FROM vakantie LIMIT 3;")
警告消息:在st_read.DBIObject(...)中:忽略查询参数, 仅使用表*
问题:为什么忽略查询参数以及如何使其工作,
答案 0 :(得分:2)
查询参数将被忽略,因为通过指定表sf假定您希望将整个表引入。只运行查询,因为您已经在该查询中指定了表。 table选项是多余的,因此默认行为将尝试读取整个表。
答案 1 :(得分:0)
只需删除表参数。
xx = st_read(connz, query = "SELECT * FROM vakantie LIMIT 3;")
我也更愿意使用RPostgres::Postgres()
驱动程序,而不是PostgreSQL()
驱动程序。定义连接对象时,还应该指定端口。
connz <- dbConnect(drv = RPostgres::Postgres(), dbname="gisdb", user = "postgres", password="postgres", host = "127.0.0.1")