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

Antonio Castillo gantonio.castillo at gmail.com
Tue Feb 2 19:51:24 EST 2010


Hello Jose

I can create the Shapefile from "ODBC:SQL Server 2008" connection, with the
OGR VRT :D

thank you!!! :P

the .ovf file
----------------------
puentes.ovf
----------------------
<OGRVRTDataSource>
    <OGRVRTLayer name="Puentes">
        <SrcDataSource>ODBC:INACMASQL</SrcDataSource>
        <SrcSQL>SELECT p.nombre AS nombre,replace(t.latitud,',','.') AS
lat,replace(t.longitud,',','.') AS long,replace(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 ogr2ogr command
-------------------------------
ogr2ogr -f "ESRI Shapefile" puentes.shp puentes.ovf


On Tue, Feb 2, 2010 at 12:33 PM, Jose Gomez-Dans <jgomezdans at gmail.com>wrote:

> 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
>



-- 
Ing Germán Antonio Castillo P.


---------------------------------------
www.AcaroLabs.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100202/25c2e96c/attachment.html


More information about the gdal-dev mailing list