I have a simple SpatiaLite geodb loaded in QGIS with one table. There is a POINT geometry field and some alphanumeric data. In some cases I can record data about a specific site, but the coordinates are not available at this time and will be retrieved and recorded later. In some other cases I have the coordinates and I want to insert them right into the geometry field, preferably by clicking on the map canvas in the same way available for adding new features (having a separate text field for the coordinates and generating the geometry from that is a no-go).

How do I add a geometry to an existing feature that was created with a NULL geometry field?


You can do this straight in spatialite. Run an UPDATE query each time you have the coordinates available like:

UPDATE point_table 
SET geometry=MakePoint(<your_new_x_coord>,<your_new_y_coord>, SRID)   
WHERE site_id=...;

This can be done from the spatialite_gui, or one of the QGIS database plugins. Does that help?

  • 1
    I should have explained that I need a GUI solution (e.g. click on a map) but maybe that can be done in one of the QGIS plugins?
    – steko
    Nov 28 '12 at 13:12
  • How ar eyou adding points to the table with a NULL geometry? I don't think that's possible in QGIS. On the other hand, you could implement a simple trigger to update the geometry column with the actual geometry whenever real x-y coordinates are added.
    – Micha
    Dec 7 '12 at 20:54
  • It is possible in some cases. See this other question that I posted right now.
    – steko
    Dec 8 '12 at 13:12

If you're after a GUI solution, you can use the "Add Part" tool (QGIS >=2.2 only). First, make your layer editable. Then in an Attribute Table select a single row with a null geometry that you want to add a geometry to. Back in the map canvas, select the "Add Part" tool and draw your geometry. The null geometry will be replaced by your newly drawn shape.

  • 1
    In QGis 3.0.2, this tool is in Edit Menu.
    – kogexo
    May 14 '18 at 16:13
  • In 2.18 I had to make the tool visible by going to View > Toolbars > Advanced Digitizing Toolbar
    – Pocketsand
    Aug 4 '18 at 11:51

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.