[R-sig-Geo] Shape to DB, DB to SpatialPolygon (solved!)

German Sanchez Hernandez german.sanchez at ais-int.com
Fri Apr 16 13:26:20 CEST 2010


Hi again!

I finally have solved my issue (enabling postgreSQL driver in (r)gdal)!

All I had to do is uninstall gdal (make clean) and install again with the correct opciones (./configure [...] --with-pg=/usr/bin/pg_config).

Thank you and regards,
Germán Sánchez

El 15/04/2010, a las 18:44, Roger Bivand escribió:

> On Thu, 15 Apr 2010, German Sanchez Hernandez wrote:
> 
> Please don't write to me directly on a posted list topic. I'm at a conference in a different time zone, have to pay for internet access, and don't use PostgreSQL myself. If you put my name as To:, other helpers will think that I'm helping and not do so themselves. The only thing that I can think of is that OGR drivers need the dependent *.so to be on the load path - did you add the PG library directory to the list searched by ldconfig?
> 
> Roger
> 
>> Other thing:
>> 
>> If I see the config.log file located in the folder which has the source of gdal, it seems PG driver is correctly installed!
>> 
>> config.log (extract):
>> 
>> $ ./configure --with-static-proj4=/usr/local/lib --with-threads --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-gif=internal --with-png=internal --with-libz=internal --without-expat --without-jasper --without-ecw --without-curl --without-dwgdirect --without-mrsid --without-jp2mrsid --without-mysql --without-odbc --without-grib --with-ogr --with-pg=/usr/bin/pg_config
>> HAVE_PG='yes'
>> PG_CONFIG='/usr/bin/pg_config'
>> PG_INC='-I/usr/include -I/usr/include/pgsql/server  -DPG_HAS_PQESCAPESTRINGCONN'
>> PG_LIB=''
>> 
>> 
>> El 12/04/2010, a las 19:14, Roger Bivand escribió:
>> 
>>> On Mon, 12 Apr 2010, Germán Sánchez Hernández wrote:
>>> 
>>>> Hi Carson (and list!),
>>>> 
>>>> I have corretly installed rgdal package in R (with some initial problems but finally working).
>>>> 
>>>> If I run ogrDrivers() no driver for PostgreSQL is listed (remember that the postgresql database is correctly running with the PostGIS extension, and I can connect through RODBC package):
>>> 
>>> The OGR driver will only be present if you have built OGR with PostGIS enabled. If you use the CRAN Windows 32-bit binary, or the CRAN extras OSX 32-bit or Windows 64-bit binaries, the driver is not included. To use PostGIS with OGR, install GDAL with PostGIS enabled, and check with:
>>> 
>>> $ ogrinfo --formats
>>> 
>>> Until you see PostGIS/PostgreSQL there, you will not see it inside R either, having installed rgdal from source. Using PostGIS effectively presupposes that you have some experience in installing software from source, and that your platform has the necessary build trains; these kinds of things rarely work "out of the box". The rgdal package as a binary has most commonly used drivers, and more will not be added, because they depend on libraries/DLLs external to GDAL/OGR.
>>> 
>>> Roger
>>> 
>>>> 
>>>>> ogrDrivers()
>>>>           name write
>>>> 1          AVCBin FALSE
>>>> 2          AVCE00 FALSE
>>>> 3             BNA  TRUE
>>>> 4             CSV  TRUE
>>>> 5             DGN  TRUE
>>>> 6             DXF  TRUE
>>>> 7  ESRI Shapefile  TRUE
>>>> 8      Geoconcept  TRUE
>>>> 9         GeoJSON  TRUE
>>>> 10         GeoRSS  TRUE
>>>> 11            GML  TRUE
>>>> 12            GMT  TRUE
>>>> 13  GPSTrackMaker  TRUE
>>>> 14            GPX  TRUE
>>>> 15            KML  TRUE
>>>> 16   MapInfo File  TRUE
>>>> 17         Memory  TRUE
>>>> 18         PCIDSK FALSE
>>>> 19            REC FALSE
>>>> 20            S57  TRUE
>>>> 21           SDTS FALSE
>>>> 22         SQLite  TRUE
>>>> 23          TIGER  TRUE
>>>> 24        UK .NTF FALSE
>>>> 25            VFK FALSE
>>>> 26            VRT FALSE
>>>> 27         XPlane FALSE
>>>> 
>>>> What am I missing?
>>>> 
>>>> Thank you!
>>>> Germán Sánchez
>>>> german.sanchez at esade.edu
>>>> 
>>>> El 08/04/2010, a las 13:17, Carson Farmer escribió:
>>>> 
>>>>> Hi Germán,
>>>>> 
>>>>> Have a look at package rgdal and the readOGR function.
>>>>> 
>>>>>> library(rgdal)
>>>>>> ?readOGR
>>>>> 
>>>>> Here is a link with a quick bit on using rgdal to access a postgis table:
>>>>> http://wiki.intamap.org/index.php/PostGIS
>>>>> 
>>>>> Regards,
>>>>> 
>>>>> Carson
>>>>> 
>>>>> On Thu, Apr 8, 2010 at 11:21 AM, Germán Sánchez
>>>>> <german.sanchez at ais-int.com> wrote:
>>>>>> Dear all,
>>>>>> 
>>>>>> I've working with spatial data since only a few months. I know how to
>>>>>> handle this kind of data in R using the sp package. I know how to load
>>>>>> shapes, plot them, merge their polygons, plotting labels, etc.
>>>>>> 
>>>>>> I have installed a postgis database and I can connect to it from R via
>>>>>> RODBC without problems. I can load a shape file (.shp and so) into the
>>>>>> database (command shp2pgsql  to create the needed .sql). It creates a
>>>>>> table with some usual fields (area, perimeter, district, etc) and the
>>>>>> special one: the_geom.
>>>>>> 
>>>>>> Now, I want to load this data to a SpatialPolygon (or
>>>>>> SpatialPolygonDataFrame) object using the RODBC driver. I would like to
>>>>>> get the same object as if I have used the "readShapePoly" function from sp
>>>>>> package directly over the .shp file.
>>>>>> 
>>>>>> Any idea? Is there a direct solution or I have to build the polygon myself?
>>>>>> 
>>>>>> Thank you,
>>>>>> Germán Sánchez
>>>>>> german.sanchez at esade.edu
>>>>>> 
>>>>>> _______________________________________________
>>>>>> R-sig-Geo mailing list
>>>>>> R-sig-Geo at stat.math.ethz.ch
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Carson J. Q. Farmer
>>>>> ISSP Doctoral Fellow
>>>>> National Centre for Geocomputation
>>>>> National University of Ireland, Maynooth,
>>>>> http://www.carsonfarmer.com/
>>>> 
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at stat.math.ethz.ch
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>> 
>>> 
>>> --
>>> 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