Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Situation:

I have a postgis vector lay that has lots of line segments (the features). I want to create a set of new layers each of which contains a subset of the features of the original layer and have these layers also stored back in postgis. Ideally with the actual features stored just once.

The only way I can see to create a new layer as opposed to load one from some source is via Layer->new which gives an option of shapefile or spatialite.

Choosing shape file I first tried to specify gid and fid attributes for the new layer but SPIT complains about duplicate field gid when I try to load it into postgis.

If I do not create any attributes for the new layer SPIT happily loads it, presumably duplicating all the features.

I am guessing this is a 'feature' rather than an oversight because if it were possible to share features between layers then then what would happen if a feature were split? If things were to work properly then all layers with referenced that feature would need updating with the new gid of the new portion.

Is this interpretation correct?

Russell

share|improve this question
1  
There is no such thing as a shared feature. You just have two copies, split one and the other stays the same. –  Nathan W Mar 10 '13 at 4:20
    
I figured that was probably the case. My problem is that over the years I have been thoroughly indoctrinated with the relational model and data normalisation ;) –  Russell Fulton Mar 11 '13 at 6:29

2 Answers 2

up vote 3 down vote accepted

Using PostGIS Manager plugin, you can create new tables in a PostGIS database.

You can also execute SQL statements such as

CREATE TABLE new_table AS SELECT * FROM old_table

to duplicate a table.

share|improve this answer

This is a somewhat older question and the correct answer has changed with recent versions of QGIS.

PostGIS Manager has been deprecated, and superseded by DB Manager which works for both PostGIS and SpatiaLite.

DB Manager is installed by default and accessible under the Database > DB Manager menu entry. That will open up the DB Manager window.

Select the database you want to add a layer too and then click Table > Create table. If you don't have a database selected when you click on the Table menu entry, the create table option will not be there.

That will open up the create table dialog which is very similar to the one accessed by Layer > New > New SpatiaLite Layer but with a different layout.

The options are mostly the same with the largest difference being that the New Spatialite Layer dialog allows access to the Specify CRS dialog which makes selecting your coordinate system easier. The Create table dialog requires that you know the SRID number beforehand to enter it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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