1

I have some tab files that are actually references to a view in a MS SQL Server table. It looks like

begin_metadata
"\IsReadOnly" = "FALSE"
"\MapInfo" = ""
"\MapInfo\TableID" = "055372be-523f-430a-b603-bbd462ad3efd"
"\DATALINK" = ""
"\DATALINK\ConnectionString" = "DSN=xxx_GIS;UID=sa;APP=MapInfo Professional®;WSID=AS00769;DATABASE=xxx_GIS"
"\DATALINK\Query" = "select ""assetID"", ""assetName"", ""ward"", ""locality"", ""GID"", ""location"", ""assetClass"", ""assetSubClass"", ""assetType"", ""hierarchy"", ""dimensionsLength"", ""MI_PRINX"", ""MI_STYLE"", ""OBJECT"" from ""NGSC_GIS"".""dbo"".""v"
"\DATALINK\Query\+1" = "w_ASSET_Bridge"""
end_metadata

In QGIS the view is like

<layer-tree-layer expanded="1" source="dbname='xxx_GIS' service='xxx_GIS' estimatedmetadata=true disableInvalidGeometryHandling='0' table=&quot;dbo&quot;.&quot;vw_ASSET_Bridge&quot; (SP_GEOMETRY) sql=" id="vw_ASSET_Bridge_1a8f7b4e_d11d_4a9e_b5ba_773aafe7014b" checked="Qt::Checked" providerKey="mssql" name="vw_ASSET_Bridge">
  <customproperties/>
</layer-tree-layer>
<layer-tree-layer expanded="1" source="../../GIS/Data/ASSET_Bridge.TAB" id="ASSET_Bridge_b0c1d436_6728_428f_a1dc_f22c15fe8c38" checked="Qt::Checked" providerKey="ogr" name="ASSET_Bridge">
  <customproperties/>
</layer-tree-layer>

Using the advice in https://alastaira.wordpress.com/ogr2ogr-patterns-for-sql-server/

I see the command should be something like

ogr2ogr -f “ESRI Shapefile” “C:\scratch\vw_ASSET_Bridge.shp” “MSSQL:server=xxx_GIS;database=xxx_GIS;trusted_connection=yes;” -sql “SELECT [ID],[GeoType],[GeoName],GEOMETRY::STGeomFromWKB([GeoShapes].STAsBinary(),28354) As [GeoShape] FROM dbo.vw_ASSET_Bridge WHERE [GeoShapes].STGeometryType() = ‘POINT'” -overwrite -a_srs “EPSG:28354”

But I am not sure what should be used for the tags in []

1 Answer 1

1

Figured it out...KISS principle as a lot of what Mapinfo/tab format required wasn't necessary in OGR

C:\OSGeo4W\bin\ogr2ogr.exe -f "MapInfo File" bridges.tab "MSSQL:Server=xxxxx;Database=_gis;User ID=user;Password=pass" -sql "SELECT * FROM dbo.vw_ASSET_Bridge" -a_srs EPSG:28354 -t_srs EPSG:4326  >>bridge_log.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.