[gdal-dev] Ogr: ExecuteSQL with MSSQL and geometry column

Chaitanya kumar CH chaitanya.ch at gmail.com
Tue Jul 17 21:33:14 PDT 2012


Benjamin,

The name 'SELECT' is intentional. We can't set it to the table's name. The
select command could be a complex one involving multiple tables.

The result layer has the native OGR format. The geometry is separate from
the attributes/fields. So, there will be no geometry column in it. You can
access the geometry like with any other ogr feature.

For a table, the geometry type is determined by reading the
dbo.geometry_columns table. For the result layer there is no easy way to do
it and is set to wkbUnknown. In any case, you should be able to use those
geometry objects like any other.


On Tue, Jul 17, 2012 at 8:07 PM, Benjamin <benjamin.lux at maxsea.fr> wrote:

> Hi,
>
> I code an application with a warper C# of Ogr.
> I have a MSSQL data base which work fine with Ogr (except this issue).
> I have a table dbo.MY_TABLE with 3 fields (D, CHART_ID, WKB_GEOMETRY).
>
> To minimise my acces to SQL Serveur (Driver MSSQLSpatial) I want to copy a
> request SQL into a Spatial Layer (with a geometry column) based on a Memory
> Driver.
> To obtain my layer I call ExecuteSQL().
>
> [code]
> string options =  "Tables=dbo.MY_TABLE(WKB_GEOMETRY);GeometryFormat=wkb;"
> serverDataSource = Ogr.Open("MSSQL:" + connectionString + options), 0);
>
> string request = "SELECT * FROM MY_TABLE WHERE CHART_ID = 'ID'"
> Layer serverLayer = serverDataSource.ExecuteSQL(request, null, "");
> [/code]
>
> I see that my layer name is "SELECT", it have 39 features but my result
> doesn't contain geometry column !
> Why ?
> serverLayer.GetGeometryColumn() returns "" and serverLayer.GetGeomType()
> returns "wkbUnknown".
>
> And the layer serverLayer ( or a layer provide by a Memory Driver) have any
> method "ChoseGeometryField" or "SetGeometryColumn" (or I have missed it).
>
>
> If I call serverDataSource.GetLayerByName("MY_TABLE").GetGeometryColumn()
> it
> work fine and result "WKB_GEOMETRY".
>
> Any suggests ?
>
> Regards,
> Benjamin.
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120718/96b0dc2b/attachment.html>


More information about the gdal-dev mailing list