Hi Benjamin,<br><br>Can you provide some more details?<br>How did you try to retrieve the geometry?<br><br><div class="gmail_quote">On Wed, Jul 18, 2012 at 8:02 PM,  <span dir="ltr"><<a href="mailto:benjamin.lux@maxsea.fr" target="_blank">benjamin.lux@maxsea.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><quote author='Benjamin'><br>
memFeature.GetGeometryRef();          // return null<br>
</quote><br>
<br>
Sorry, but no.<br>
After a call to SQLExecute(), Ogr framwork doesn't recognize any geometry in my feature.<br>
If you have a clue why that ?<br>
<br>
<quote author='chaitanya_ch'><br>
<div><div class="h5">Benjamin,<br>
<br>
The mssql driver already does the conversion from wkb in the database to<br>
the native ogr geometry format. You don't have to create a temporary wkb<br>
geometry and then the ogr geometry.<br>
<br>
You can simply do this:<br>
[code]<br>
Geometry memGeom = memFeature.GetGeometryRef()<br>
[/code]<br>
<br>
On Wed, Jul 18, 2012 at 6:31 PM, Benjamin <<a href="mailto:benjamin.lux@maxsea.fr">benjamin.lux@maxsea.fr</a>> wrote:<br>
<br>
> Sorry, I was not clear.<br>
><br>
> I resume from the beginning.<br>
><br>
> I work with a warper C# of Ogr.<br>
> I have a table dbo.MY_TABLE with 3 fields (D, CHART_ID, WKB_GEOMETRY) in a<br>
> SQL server Database (in SQL Azure exactly).<br>
><br>
> *My aim is to work with a copy* (in a<br>
> <a href="http://www.gdal.org/ogr/drv_memory.html" target="_blank">http://www.gdal.org/ogr/drv_memory.html</a> Memory DataSource ) of a SQL<br>
> statement result executed on a MSSQL DataSource.<br>
><br>
> Actually I can work with usuals methods with this MSSQL DataSource.<br>
> Note that I have not geometry_column table in my SQL Serveur DataBase, I<br>
> use<br>
> <a href="http://www.gdal.org/ogr/drv_mssqlspatial.html" target="_blank">http://www.gdal.org/ogr/drv_mssqlspatial.html</a> driver options .<br>
><br>
> [code]<br>
> string driverOptions =<br>
> "Tables=dbo.MY_TABLE(WKB_GEOMETRY);GeometryFormat=wkb;"<br>
> serverDataSource = Ogr.Open("MSSQL:" + connectionString + driverOptions),<br>
> 0);<br>
><br>
> serveurDataSource.GetLayerCount(); // It works fine.<br>
> [/code]<br>
><br>
> So I tried a call to<br>
><br>
> <a href="http://www.gdal.org/ogr/classOGRDataSource.html#aa6acc228db6513784a56ce12334a8c33" target="_blank">http://www.gdal.org/ogr/classOGRDataSource.html#aa6acc228db6513784a56ce12334a8c33</a><br>
> SQLExecute() .<br>
> [code]<br>
> string request = "*SELECT * FROM MY_TABLE WHERE CHART_ID = 'ID'*"<br>
> Layer serverLayer = serverDataSource.ExecuteSQL(request, null, "");<br>
> [/code]<br>
><br>
> But unfortunately, I have not geometry field in the result.<br>
> [code]<br>
> serveurLayer.GetGeometryColumn();  //*return ""*<br>
> serveurLayer.GetGeomType();          //*return wkbUnknown*<br>
> [/code]<br>
><br>
> But I have my 3 fields in serveurLayer !<br>
> [code]<br>
> serverLayer.GetLayerDefn().GetFieldCount();                //return 3<br>
> serverLayer.GetLayerDefn().GetFieldDefn(0).GetName(); //return "D"<br>
> serverLayer.GetLayerDefn().GetFieldDefn(1).GetName(); //return "CHART_ID"<br>
> serverLayer.GetLayerDefn().GetFieldDefn(2).GetName(); //*return<br>
> "WKB_GEOMETRY"*<br>
> [/code]<br>
><br>
> So I want to copy this layer in a Memory Layer to minimise acces to my SQL<br>
> Server and work faster.<br>
> [code]<br>
> Driver memDriver = Ogr.GetDriverByName("Memory");<br>
> DataSource memDataSource =<br>
> memDriver.CreateDataSource(GetWorkPath("nomimprobale"), null);<br>
> Layer memLayer = memDataSource.CopyLayer(serverLayer, layerName, null);<br>
> [/code]<br>
><br>
><br>
> Now,* I have to fetch my geometries*, so have thought to a trick like this<br>
> :<br>
> [code]<br>
> byte[] memWkb =<br>
><br>
> System.Text.Encoding.UTF8.GetBytes(memFeature.GetFieldAsString("WKB_GEOMETRY"));<br>
> Geometry memGeom = Geometry.CreateFromWkb(memWkb);<br>
> [/code]<br>
> Because I can't use memFeature.GetGeometryRef()<br>
> [code]<br>
> memFeature.GetLayerCount();                                // return 39<br>
> Feature memFeature = memLayer.GetNextFeature();  // don't return null<br>
> memFeature.GetGeometryRef();                             // *return null*<br>
> [/code]<br>
><br>
> But I don't know if I have to use UTF8, ASCII, Unicode or other.<br>
> If you know what encoding is use, or better an other trick to have a<br>
> geometry in my memLayer or serverLayer I heard you with interest !<br>
><br>
><br>
> Sorry for my spelling, English isn't my native tongue language.<br>
><br>
> Benjamin<br>
><br>
><br>
> Ps : link to the thread:<br>
><br>
> <a href="http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831.html</a><br>

><br>
> <a href="http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831.html</a><br>

><br>
><br>
><br>
> Even Rouault wrote<br>
> ><br>
> > Selon Benjamin &lt;benjamin.lux@&gt;:<br>
> ><br>
> >> "You can access the geometry like with any other ogr feature."<br>
> >><br>
> ><br>
> > Hopefully, memFeature.GetGeometryRef() should do it !<br>
> > _______________________________________________<br>
> > gdal-dev mailing list<br>
> > gdal-dev@.osgeo<br>
> > <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
> ><br>
><br>
><br>
> --<br>
> View this message in context:<br>
> <a href="http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831p4989072.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831p4989072.html</a><br>

> Sent from the GDAL - Dev mailing list archive at Nabble.com.<br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
><br>
<br>
<br>
<br>
--<br>
Best regards,<br>
Chaitanya kumar CH.<br>
<br>
<a href="tel:%2B91-9494447584" value="+919494447584">+91-9494447584</a><br>
17.2416N 80.1426E<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></div></quote><br>
Quoted from:<br>
<a href="http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831p4989092.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/gdal-dev-Ogr-ExecuteSQL-with-MSSQL-and-geometry-column-tp4988831p4989092.html</a><br>

</blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br><br>+91-9494447584<br>17.2416N 80.1426E<br>