[R-sig-Geo] RE : RE : rgdal problem when connecting with postgres

Cédric Briand cedric.briand at lavilaine.com
Mon Feb 1 22:12:40 CET 2010


Oh, I saw this one but did not continue as I did not find the pexports in the Mingw distributed with Rtools. It is not provided and must be downloaded. Getting help from Mingw is difficult as all their pages currently point to some commercial source....
So following your direction I've finally succeded in building the package. To say frankly it was difficult to me (I never included dll in my packages so far). So I'm providing other users with detailed instructions on how to proceed.

##  notes for building gdal against OSGeo4W (modified from Roger Bivand)
## 1- download rgdal sources http://cran.r-project.org/web/packages/rgdal/index.html
## in the following I just copied it in c:\
## 2- Run in OSGeo4W console, after setting:
set OSGEO4W_BUILD=yes
set GDAL_HOME=%OSGEO4W_ROOT%

## 3-get the Rdll.lib
## MinGW is avalaible with Rtools
## install pexports (available at http://sourceforge.net/projects/mingw/files/ somewhere down the long list ...
cd C:\Program Files\R\R-2.10.1\bin
C:\Rtools\MinGW\bin\ pexports R.dll > R.exp
## using visual c++ (vc9) command line url: http://www.microsoft.com/express/Downloads/#2008-Visual-CPP
cd C:\Program Files\R\R-2.10.1\bin
lib /def:R.exp /out:Rdll.lib
cd C:/rgdal/src
cl /MT /Ox /EHsc /D "WIN32" /c /I "C:/Program Files/R/R-2.10.1/include" /I C:/OSGeo4W/include /I "C:\Program Files\Microsoft Visual Studio 9.0\VC\include" /D OSGEO4W *.cpp
link /dll /out:rgdal.dll /def:rgdal.def *.obj "C:/Program Files/R/R-2.10.1/bin/Rdll.lib" /libpath:"C:\Program Files\Microsoft Visual Studio 9.0\VC\lib" /libpath:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" /libpath:"C:\OSGeo4W\lib" gdal_i.lib proj_i.lib
## 4. Ensure the configure.win, Makefile.win and RGDAL.def are all correct. 
## these files are found in rgdal and rgdal/src
## set the location of GDAL_HOME in configure.win (GDAL_HOME="C:/OSGeo4W") for default OSGeo4W install
-//-- start configure.win
#!/bin/sh
if test -z "$GDAL_HOME" ; then
    GDAL_HOME="C:/OSGeo4W"
fi
echo "GDAL_HOME=${GDAL_HOME}" > src/Makeconf.win
echo "using GDAL_HOME: ${GDAL_HOME}"
if test -z "$OSGEO4W_BUILD" ; then
  if test -z "$R_PACKAGE_DIR" ; then
    R_PACKAGE_DIR=${DPKG}
 fi
  mkdir "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/adrg.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/cblas.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/dted.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/fribidi.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/gdiplus.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/gdal15.dll "${R_PACKAGE_DIR}/libs"
  cp ${GDAL_HOME}/bin/gdal16.dll "${R_PACKAGE_DIR}/libs"
  echo "OSGEO= " >> src/Makeconf.win
else
    echo "OSGEO=-DOSGEO4W" >> src/Makeconf.win
fi
-//-- end configure.win

##   RGDAL.def as supplied in rgdal/src (no modification there)
##   Place Makefile.win in src/, containing a single line:
all:
##5. Install package (my rdal sources are still in c:/)
## CD C:\
C:\"Program Files"\R\R-2.10.1\bin\Rcmd INSTALL --build rgdal
## Note if this step does not work look if you have the Rtools properly installed and configured (especially the path)
## Then copy manually all dll of c:/OSGeo4W/bin in the newly rgdal/libs 
##Post-installation, start R from the OSGeo4W console (command line). If you want
##to check that the OSGeo4W-aware rgdal is present, check the reported support
##file locations, and consider running:
source(system.file("OSGeo4W_test", package="rgdal"), echo=TRUE)
also list drivers with  ogrDrivers() PostgresSQL should be on the list

The test has worked fine but
rdGDAL> GDALinfo(system.file("external/test.ag", package="sp")[1])
Erreur dans .Call("RGDAL_GetMetadata", x, NULL, PACKAGE = "rgdal") : 
  le nom C de symbole "RGDAL_GetMetadata" est introuvable dans la DLL pour le package "rgdal"
De plus : Messages d'avis :
1: In getGeoTransFunc(dataset) : GeoTransform values not available
2: In getGeoTransFunc(dataset) : GeoTransform values not available
3: In x[20:50, 20:50] : GeoTransform values not available
4: In x.gdal[, , 3] : GeoTransform values not available
5: In x.gdal[] : GeoTransform values not available
6: In asMethod(object) : GeoTransform values not available
 

and unfortunately

Erreur dans .Call("R_OGR_types", as.character(dsn), as.character(layer),  : 
  le nom C de symbole "R_OGR_types" est introuvable dans la DLL pour le package "rgdal"


Thanks again for your answers

Cédric

________________________________________
De : Roger Bivand [Roger.Bivand at nhh.no]
Date d'envoi : lundi 1 février 2010 09:51
À : Cédric Briand
Cc : r-sig-geo at stat.math.ethz.ch
Objet : Re: RE : [R-sig-Geo] rgdal problem when connecting with postgres

On Sun, 31 Jan 2010, Cédric Briand wrote:

> Dear Roger
>
> Thank you for your answer.
>
> I have done the following : -----------------------------------------
> Run in OSGeo4W console, after setting: set OSGEO4W_BUILD=yes set
> GDAL_HOME=%OSGEO4W_ROOT% download rgdal sources cd C:/rgdal/src using
> visuel c++ (vc9) command line cl /MT /Ox /EHsc /D "WIN32" /c /I
> "C:/Program Files/R/R-2.10.1/include" /I C:/OSGeo4W/include /I
> "C:\Program Files\Microsoft Visual Studio 9.0\VC\include" /D OSGEO4W
> *.cpp ------------------------------------------------------- at this
> point, following your insctructions, I need a rdll.lib, and was not able
> to produce it ...

Cédric:

This is discussed in README.packages in src/gnuwin32 in the source -
online (for the development version) at:

https://svn.r-project.org/R/trunk/src/gnuwin32/README.packages

or 2.10.1:

https://svn.r-project.org/R/tags/R-2-10-1/src/gnuwin32/README.packages

your error messages suggest that trying the alternative

pexports R.dll > R.exp

might be worth trying. This step is needed for building any source package
under Windows using VC++, so either make R.exp or using pexports should
work once everything is lined up (PATH, etc.).

For me with a command line in R-2.10.1/bin, "pexports R.dll > R.exp" does
work, as does "lib /def:R.exp /out:Rdll.lib", but your mileage may vary.

Roger


>
> I understand I have to download the source and try the following code, but it fails.
>
> C:\R-2.10.1\src\gnuwin32>make R.exp
> -------------------------------------------------
> gcc -std=gnu99 -I../include -I. -I../extra -DHAVE_CONFIG_H -DR_DLL_BUILD  -O3 -W
> all -pedantic   -c console.c -o console.o
> console.c:23:20: error: config.h: No such file or directory
> console.c:73: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Ch
> aracterMode'
> console.c: In function 'console_normalkeyin':
> console.c:1357: error: 'CharacterMode' undeclared (first use in this function)
> console.c:1357: error: (Each undeclared identifier is reported only once
> console.c:1357: error: for each function it appears in.)
> console.c:1357: error: 'RGui' undeclared (first use in this function)
> make: *** [console.o] Error 1
> ---------------------------------------------------
> Cédric
>
> ________________________________________
> De : Roger Bivand [Roger.Bivand at nhh.no]
> Date d'envoi : vendredi 29 janvier 2010 20:11
> À : Cédric Briand
> Cc : r-sig-geo at stat.math.ethz.ch
> Objet : Re: [R-sig-Geo] rgdal problem when connecting with postgres
>
> On Fri, 29 Jan 2010, Cédric Briand wrote:
>
>> Dear list members
>> We are using R 2.10.1 and rgdal Version: 0.6-20, and are working with
>> windows XP.
>
> If you mean the Windows binary rgdal package, then the answer is in
>
> file.show(system.file("README", package="rgdal"))
> file.show(system.file("README.windows", package="rgdal"))
>
> The Windows binary package builds the minimal set of drivers, with only
> one external dependency (expat for reading GPX and KML). The file refered
> to describes how you might build rgdal from source, using FWTools or
> OSGEO4W as the provider of GDAL and its dependent DLLs. If you do try this
> out (look for the chunk beginning: "Initial notes for OSGeo4W"), and if:
>
> source(system.file("OSGeo4W_test", package="rgdal"), echo=TRUE)
>
> works, as well as PostGIS access, please let me know.
>
> Roger
>
>
>> Following the nice example found at
>> http://wiki.intamap.org/index.php/PostGIS<http://wiki.intamap.org/index.php/PostGIS>
>> we tried to connect to our postgres database
>>
>
> PS. That example was run on Linux with GDAL built with PostGIS, and rgdal
> installed as a source package.
>
>> library(rgdal)
>> trial = readOGR("PG:dbname=CCM", "riversegments")
>>
>>
>> This does not work. We have tried to use ogr2ogr and examples found at
>>
>> http://www.bostongis.com/?content_name=ogr_cheatsheet
>>
>> and they work fine particularly we were able to connect to our database using the following script
>>
>>
>> C:\OSGeo4W\bin\ogr2ogr -f "ESRI Shapefile" C:\base\basesig\essai.shp PG:"host=localhost user=postgres dbname=CCM password=postgres port=5433" "riversegments
>>
>>
>>
>>
>>
>> As this works we translated the more complex dsn into the rgdal command line
>>
>>
>>
>> require(rgdal)
>>
>> readOGR(dsn="PG:host=locahost user=postgres dbname=CCM password=postgres port=5433",layer="riversegments")
>>
>>
>>
>> but it always returns a "Cannot open file" error :
>>
>>
>>
>>> require(rgdal)
>>
>> Le chargement a n?cessit? le package : rgdal
>>
>> Le chargement a n?cessit? le package : sp
>>
>> Geospatial Data Abstraction Library extensions to R successfully loaded
>>
>> Loaded GDAL runtime: GDAL 1.6.2, released 2009/07/31
>>
>> Path to GDAL shared files: C:/Program Files/R/R-2.10.0/library/rgdal/gdal
>>
>> Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
>>
>> Path to PROJ.4 shared files: C:/Program Files/R/R-2.10.0/library/rgdal/proj
>>
>>> readOGR(dsn="PG:host=localhost dbname=CCM user=postgres passwd=postgres port=5433",layer="riversegments")
>>
>> Erreur dans ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding = input_field_name_encoding) :   Cannot open file
>>
>>
>> The ogrInfo in command line found at 'C:\OSGeo4W\bin\ogrInfo.exe' does seem to work (it does not return any error)
>>
>>
>>
>> The reason behind this failure seems to be that PostgresSQL is not listed in the drivers availaible with the package.
>>
>>> ogrDrivers()
>>
>>             name write
>>
>> 1          AVCBin FALSE
>>
>> 2          AVCE00 FALSE
>>
>> 3             BNA  TRUE
>>
>> 4             CSV  TRUE
>>
>> 5             DGN  TRUE
>>
>> 6  ESRI Shapefile  TRUE
>>
>> 7      Geoconcept  TRUE
>>
>> 8         GeoJSON  TRUE
>>
>> 9             GML  TRUE
>>
>> 10            GMT  TRUE
>>
>> 11            GPX  TRUE
>>
>> 12            KML  TRUE
>>
>> 13   MapInfo File  TRUE
>>
>> 14         Memory  TRUE
>>
>> 15            REC FALSE
>>
>> 16            S57  TRUE
>>
>> 17           SDTS FALSE
>>
>> 18          TIGER  TRUE
>>
>> 19        UK .NTF FALSE
>>
>> 20            VRT FALSE
>>
>> 21         XPlane FALSE
>>
>>
>>
>> After many trials we are at a loss on how to add a driver to the drivers in R. So any hint would be really valuable.
>>
>>
>>
>> C?dric
>>
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>>
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list