Skip to content

passing SQL through readOGR()

4 messages · Tom Gottfried, Roger Bivand, etiennebr

#
Hi Etienne,

so far I only did it with points:

data_frame <- sqlQuery(odbcConnect("yourdatabase"),
	"SELECT attr, ST_X(the_geom) AS x, ST_Y(the_geom) AS y FROM yourtable WHERE ...")
coordinates(data_frame) <- ~x+y

regards,
Tom

Am 15.11.2010 17:01, schrieb Etienne Bellemare:
#
On Mon, 15 Nov 2010, Tom Gottfried wrote:

            
Because "OGR SQL has been reimplemented for GDAL/OGR 1.8.0", see: 
http://www.gdal.org/ogr/ogr_sql.html, and the RFC: 
http://trac.osgeo.org/gdal/wiki/rfc28_sqlfunc, it doesn't seem sensible to 
make changes in readOGR() now for released GDAL/OGR 1.7.3. As rgdal is now 
on R-Forge, I would welcome contributions and other input so that a 
new-generation readOGR() is ready soon after GDAL/OGR 1.8.0 is released, 
perhaps later this year or early next year.

Roger

  
    
8 days later
#
On Wed, 24 Nov 2010, etiennebr wrote:

            
Thanks for the offer, rgdal is now hosted on R-forge for anonymous 
checkout. The prefered approach is to find out how to use:

http://www.gdal.org/ogr/ogr_sql.html

and

http://trac.osgeo.org/gdal/wiki/rfc28_sqlfunc

and its forthcoming extensions in GDAL 1.8.0 in setting an attribute 
filter before importing using OGR, rather than looking at drivers, which 
OGR handles. The same attribute SQL selections should then work across all 
drivers. It may be possible to try a prototype with the existing mixture 
of R and C/C++ in readOGR(), but a fresh prototype with more done in C/C++ 
is probably the best bet, passing the SQL string out to the OGR SQL 
engine directly, and letting it do all the work.

Roger