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

Mathieu Basille basille.web at ase-research.org
Wed Nov 30 15:56:20 CET 2016


Hey Vil,

I know it doesn't answer the problem of using rgdal to load PostGIS layers
(especially rasters), but have you tried to use rpostgis::pgGetRast to load
rasters in R? Might not be the most computer efficient, but should get you
there...

Mathieu.


On 11/30/2016 05:09 AM, Vilem Ded wrote:
> 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 
> 
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 

Mathieu Basille

basille at ufl.edu | http://ase-research.org/basille
+1 954-577-6314 | University of Florida FLREC

  « Le tout est de tout dire, et je manque de mots
  Et je manque de temps, et je manque d'audace. »
  — Paul Éluard

This message is signed to guarantee its authenticity.
For a true private correspondence, use my public key
to encrypt your messages:

  http://mathieu.basille.net/pub.asc

Learn more: http://mzl.la/1BsOGiZ

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20161130/280ecb59/attachment.bin>


More information about the R-sig-Geo mailing list