[R-sig-Geo] PostGIS layer to R using OGR driver imports unwanted raster column as String

Vilem Ded Ded.V at seznam.cz
Wed Nov 30 11:09:24 CET 2016


Hi, 
right to the point. I  am trying to load spatial layer from postgis database to R:

obj <- rgdal::readOGR(dsn="PG:dbname=DB host=HOST user=USER password=PSSWD port=5432", layer = "SCHEMA.TABLE(LAYER)")

My table contains more spatial  columns/layers, these are not loaded from database. Thats OK. The only  think is the raster layer, which is not excluded and it is imported to obj at data dataframe as String column. Quite annoying thing in case of big rasters which I dont even want to be loaded. rgdal:ogrInfo() report this column as String, so no surprise that it is loaded as such.

I have tried to export layer using ogr2ogr with command:
ogr2ogr -f "ESRI Shapefile" abc.shp PG:"dbname=DB host=HOST user=USER password=PSSWD port=5432" "SHEMA.TABLE(SPATIAL_COLUMN)"

The raster column was still there, but the String was much shorter - 254 (obviously it was converted/cut to type character(254)). 

Is this an issue? Because it's seems to me like one.

Thank you
Dead Vil


output of  rgdal::ogrInfo():
Source: "PG:dbname=DB host=HOST user=USER password=PSSWD port=5432", layer: "schema.laketable(lt_shoreline_pol)"
Driver: PostgreSQL; number of rows: 2 
Feature type: wkbPolygon with 2 dimensions
Extent: (403229.3 5598032) - (427369.2 5612437)
CRS: +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs  
Number of fields: 3 
          name type length typeName
1      lt_lake    4     40   String
2 lt_elevation    2      0     Real
3 lt_depthrast    4      0   String

output of sessionInfo():
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)
locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] data.table_1.9.7 vegan_2.4-1      lattice_0.20-33  permute_0.9-4    wkb_0.3-0        lubridate_1.5.6  RODBC_1.3-13    
 [8] geosphere_1.5-5  raster_2.5-8     rgeos_0.3-19     rgdal_1.1-10     sp_1.2-3        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.4    MASS_7.3-45    grid_3.2.4     nlme_3.1-128   magrittr_1.5   stringi_1.0-1  Matrix_1.2-4   tools_3.2.4   
 [9] stringr_1.0.0  parallel_3.2.4 cluster_2.0.3  mgcv_1.8-12 






More information about the R-sig-Geo mailing list