[GRASS-user] multiple polygons with same cat

Dave Roberts dvrbts at ecology.msu.montana.edu
Tue Nov 26 05:43:49 PST 2013


Thanks Markus.  This has me on the right track, but I haven't gotten it 
all to work yet.

v.category map=geo type=centroid op=add layer=2

refused to work without a new output map, so

v.category inp=geo  out=new_geo op=add layer=2

produced a new vector map where the cats are unique for each polygon.

doing d.what.vect new_geo shows the old data in layer 1 and the new data 
in layer 2

   Curiously, there are now 3938 polygons (instead of 1082).  If I do a
v.db.connect to a table in Postgres and then v.to.db move over the cat 
and coor data psql shows that the first 2725 records are null (except 
for cat) and the X,Y coordinates start at cat 2726, giving me 1212 
polygons with real data.

    I could maybe delete the first 2726 records and join this new table 
to the one with the stratigraphy data on the X and Y coordinates, but 
doing exact equality on floating point numbers is madness.

Any ideas?

Thanks, Dave

On 11/26/2013 02:25 AM, Markus Metz wrote:
> On Tue, Nov 26, 2013 at 3:39 AM, Dave Roberts
> <dvrbts at ecology.msu.montana.edu> wrote:
>> Friends,
>>
>>    I'm not exactly a newbie, but still yet quite naive in GRASS.  This seems
>> like a simple problem, but I suspect unforeseen problems with the simple
>> solution.
>>
>>    I have imported a surficial geology map from a shapefile.  There are 1082
>> polygons.  Each of the polygons with the same surficial geology (e.g Agn,
>> Archean gneiss) has the same cat (i.e. there are 29 polygons with cat=3).  I
>> would like to add several columns to this table (e.g. geologic era and
>> primary lithology (e.g. granite vs limestone)).
>>
>>     I normally associate all vector maps with a table in PostgreSQL using cat
>> as the primary key (i.e. v.db.connect -o key=cat), but that clearly won't
>> work here.  I could rename the column 'cat' in the DBF file, and add a new
>> column with values 1-1082 as cat.
>
> That does not work because the geometries don't get new categories.
>
>> If I save that as a new DBF file in a new
>> shapefile directory, when I re-import with v.in.ogr will it necessarily get
>> it right?  I.e, will GRASS associate the vertices the first polygon in the
>> shapefile with the first row in the DBF file?  I only ask because PostgreSQl
>> (like most DBMSs) does not guarantee the records to be in any specific
>> order, and perhaps shapefiles don't either?
>
> Shapefiles (using DBF) require the records in a specific order. GRASS
> vectors do not require records to be in a specific order, they link
> geometries to the appropriate record with the key column.
>>
>>      Is there a simple way to renumber the polygons 1 through 1082 that
>> maintains integrity and allows me to connect the vector coverage to
>> PostgreSQL instead of DBF?
>
> v.category map=geo type=centroid op=add layer=2
>
> That will create a new layer where each area has a unique category.
> The original layer where several areas share the same category is
> preserved. You can add a new table to this layer with v.db.addtable
> layer=2. Then you can transfer attributes from one layer to another
> with v.to.db.
>
> HTH,
>
> Markus M
>

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts at montana.edu
Montana State University
Bozeman, MT 59717-3460


More information about the grass-user mailing list