Quantum GIS copy paste geom and attributes into Postgis
Problem: I have a shapefile with 5000 points and I have a Postgis table that I want to add data to from the shapefile. I want to select 1500 points from the shapefile and use copy paste into the Postgis table.
process:
What to do?
process:
- open qgis add the shapefile layer add the postgis layer
- start editing the postgis layer (this is where the new data is going)
- select the 1500 points using the table editor based on criteria
- select copy
- select the postgis layer from the layers menu on the left
- select paste
- data is pasted
- save
- ERROR
Änderungen am Layer poi konnten nicht gespeichert werden
Fehler: FEHLER: 14 Objekte nicht hinzugefügt.
Datenlieferantenfehler:
PostGIS-Fehler beim Attributhinzufügen: ERROR: duplicate key value violates unique constraint "poi_pkey"
DETAIL: Key (id)=(0) already exists.
What to do?
- open attribute table of postgis layer and you should see the data selected and make sure you only see the selected data
- click field calculator
- select edit existing field
- select the ID field i want to update with values
- type $rownum in the bottom field
- click ok
- selected fields will now have a number 1, 2, 3 (this is still a problem because the values 1 for example are already given and cause the Primary Key constraint to yell, so we need to have a sort of auto increment value.
- now select the field calculator again with the same data still selected
- select only selected checkbox
- select update existing field checkbox
- now type $id+94500
$id is the field id
94500 is the highest number in the id field currently so we are just adding 1 for the first row, then adding 2 for the second row...etc for only our selected values. Now we have added our data and updated the ID field to meet the primary key and NOT NULL constraints. - click ok
- done
what happe
Comments
Post a Comment