I'm not able to reproduce this in QGIS 2.2 Windows, c3a2817.
If other versions behave differently, or if you're continuing to have this problem, you can probably set up a PostgreSQL trigger on the table as a workaround:
Using this example table:
CREATE TABLE testing (gid serial PRIMARY KEY, geom geometry(Polygon, 4326));
Here's a trigger function that will assign a new gid
where needed:
CREATE OR REPLACE FUNCTION testing_insert_trigger()
RETURNS trigger AS
$$
BEGIN
IF EXISTS (SELECT 1 FROM testing WHERE gid = NEW.gid) THEN
NEW.gid := nextval('testing_gid_seq'::regclass);
END IF;
RETURN NEW;
END;
$$ language 'plpgsql';
Binding the function to the table...
CREATE TRIGGER testing_insert
BEFORE INSERT ON testing
FOR EACH ROW EXECUTE PROCEDURE testing_insert_trigger();
This will automatically assign new IDs where the gid
already exists. For example, the following query will now duplicate all data in the table instead of failing:
INSERT INTO testing (SELECT * FROM testing);
Of course, this approach can compromise the intent of your primary key, so use it carefully.
You need to use Join attributes by location
from Processing Toolbox -> QGIS geoalgorithms -> Vector General tools -> Join attributes by location
which allows you to copy the attribute of one of the two layers into the other using various Geometric Predicates
including intersects
and touches
as you can see below:
If you want to transfer all records, even if they is no spatial connection, you need to choose Keep all records
, otherwise you need to choose Only keep matching records
located under Joined Table.
Best Answer
To copy features from one shapefile to another you select features from shapefile a and use copy. next step is to activate edit mode in your aimed shapefile b. you can open the attribut table
next it should look like this
to check everything went fine, add an area row and calculate the area to make sure there is a geometry added