[gdal-dev] trying create a new SHP with Ogr2ogr from ODBC: SQL SERVER

Jose Gomez-Dans jgomezdans at gmail.com
Tue Feb 2 12:33:05 EST 2010


Hi

On 2 February 2010 17:11, Antonio Castillo <gantonio.castillo at gmail.com>wrote:

> ogr2ogr -f "ESRI Shapefile" -a_srs "EPSG:4326" "puentes.shp"
> "ODBC:INACMASQL"  -nlt POINT -sql "SELECT
> p.nombre,t.latitud,t.longitud,t.altura FROM puente p,trayectoria t WHERE
> p.id_trajectory = t.id_trayectoria"


I think your problem stems from the fact that the DBF created in the
previous command has two fields that need to be related to a point geometry.
There's an example in how to translate this query into a virtual dataset,
which can then be translated into a shapefile easily in <
http://www.gdal.org/ogr/drv_vrt.html>. Not tested, but basically create a
file called the following file:

<OGRVRTDataSource>
    <OGRVRTLayer name="MyQuery">
        <SrcDataSource>ODBC:INACMASQL</SrcDataSource>
*        <SrcSQL*>SELECT p.nombre AS nombre,t.latitud AS
lat,t.longitud AS long,t.altura AS altura FROM puente p,trayectoria t
WHERE p.id_trajectory = t.id_trayectoria</SrcSQL>
	<GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
	<GeometryField encoding="PointFromColumns" x="long" y="lat"/>
    </OGRVRTLayer>
</OGRVRTDataSource>


and then convert it into a Shapefile using ogr2ogr.

Hope that helps!
Jose
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100202/51e9c7e7/attachment.html


More information about the gdal-dev mailing list