2

I have a Layer, load from a WKT file in QGIS with and geometry field called 'geometry':

This is the wkt source:

type;label;geometry
0x10e04;Rego de San Xurxo;LINESTRING(-8.00676 43.54270,-8.00953 43.54159,-8.01118 43.54088,-8.01197 43.54056,-8.01208 43.54049)
...

I load into a layer with (Layer-Add Layer->Add delimited text layer) and all OK, then i 'Save as' ->SpatiaLite.... and I get a file example.sqlite. If I load into and SQlite Browser, i can see a field called "geometry" with BLOB content.

How is the equivalent command to QGIS "save as -> Spatialite" in ogr2ogr from the originl WKT file ?

All my attempts give me a example.sqlite but with a field "geometry" with text content, and this file can not be loaded into QGIS.

2

One option is to create a VRT with your WKT as the source, for instance:

<OGRVRTDataSource>
    <OGRVRTLayer name="linedata">
       <SrcDataSource>input.csv</SrcDataSource>
      <GeometryType>wkbMultiLineString</GeometryType>
 <LayerSRS>EPSG:3857</LayerSRS>
 <GeometryField encoding="WKT" field='geom' > </GeometryField >
     </OGRVRTLayer>
</OGRVRTDataSource>

You can then convert your VRT (e.g. input.vrt) to a Spatialite database (output.db) as follows:

ogr2ogr -f SQLite output.db input.vrt
  • Thank you very much, dmci, I got it, now I have a field called 'geom' with geometry at BLOB format, but also I have a 'duplicate' field with geometry into original 'string' format. Is it possible to avoid the original string field into new sqlite file? – Juanma Font Dec 21 '16 at 17:22
  • 1
    maybe ensure that you use either 'geom' or 'geometry' in both your WKT and VRT, i.e. don't mix them. – dmci Dec 21 '16 at 17:32
  • Thanks dmci. I respong mysefl: Add tags <Field name='field' src="source_field"/> for every field I need (avoid not necessary) I will get only selected fields from source. ;) I'm happy now... thanks. – Juanma Font Dec 21 '16 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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