5

I'm using QGIS 2.2.0. I add a vector to a vector layer and save the file. After I reopen the .qgs file, the new vector is not shown.

(1) Click 'Toggle Editing'

enter image description here

(2) Click 'Add Feature' and draw a polyline.

enter image description here

(3) Click 'Save Layer Edits'

enter image description here

(4) Click 'Save'

enter image description here

  • What type of file is my_line? – Michael Stimson Jun 16 '14 at 0:46
  • It is a vector layer created using layer = QgsVectorLayer('LineString', 'my line' , 'memory') and QgsMapLayerRegistry.instance().addMapLayers([layer]) – wannik Jun 16 '14 at 1:04
  • 3
    An in-memory layer is not persisted. You need to save it as a shapefile or other file system type. They are intended only as a temporary storage for processing etc. – Michael Stimson Jun 16 '14 at 1:12
  • @MichaelMiles-Stimson Thank you very much for the info. I'm now able to save the vector. – wannik Jun 16 '14 at 1:34
  • You're welcome. I'll turn that into an answer in case anyone else encounters this problem. – Michael Stimson Jun 16 '14 at 1:37
8

In memory layers are temporary, they don't get saved when you call save edits. They are only intended to be temporary and should be saved as a file system type (like shapefile) if you intend to keep their edits.

You should probably call QgsVectorLayer::setCoordinateSystem() on the layer before editing and definitely before saving. All spatial data should have a coordinate system, even if you make it the same as the canvas.

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.