[GRASSLIST:8500] Re: perimeter

Leonardo Lami lami at faunalia.it
Wed Oct 5 05:19:23 EDT 2005


Thi is the solution of Hamish.
You must make some changes to match it with your data but the result is very 
good.

Thanks to Hamish

Leonardo


#######################

v.to.db was failing because my boundaries did not have cats, but back
to the central problem:


To make a report of the perimeters of all areas it takes the following,
which is not easy! (maybe a bit simpler with use of 'v.reclass rules=' ?)


#!/bin/sh
# calc the coastline lengths of island groups
# (assume same fractal-depth; use for ratios only; yada, yada, yada)

# add categories to boundaries, starting with 1000 (something bigger
#  than number of existing cats for clarity).
v.category in=t_area out=t_area_lab_bdy type=boundary cat=1000 step=1

# export sides to a text file; keep only existing side
#  (areas do not touch so we can get away with this)
v.to.db t_area_lab_bdy -p op=sides col=l,r type=boundary | \
  sed -e 's/|-1//' | sed -e 1d > t_area_bdy.prn

# extract only boundaries
v.extract in=t_area_lab_bdy out=t_area_bdy type=boundary

# convert to lines (optional)
v.type in=t_area_bdy out=t_area_line type=boundary,line

# add new column to hold the original area's cat number
map=t_area_line
echo "ALTER TABLE $map ADD area_cat integer" | db.execute

# create SQL command file
cat t_area_bdy.prn | \
  awk -F'|' '{ printf("echo \"INSERT INTO $map (cat, area_cat) VALUES (%d, 
%d)\" | db.execute\n", $1, $2) }' \
    > t_area_bdy_exe

# run the SQL command file (populate with a series of db.execute commands)
. t_area_bdy_exe

# make a new vector using the area_cat column from 'v.to.db op=sides' as
#  the cat number
v.reclass in=t_area_line out=t_area_line2 column=area_cat

# copy original table to the new vector and connect it
db.copy from_table=t_area to_table=t_area_line2
v.db.connect map=t_area_line2 table=t_area_line2

# we now have a line vector file with the category numbers belonging to
#   the original touching area as the cat!


# calculate the perimeter length for each area into new cstln_mtr column
echo "ALTER TABLE t_area_line2 ADD cstln_mtr double" | db.execute
v.to.db t_area_line2 option=length col=cstln_mtr

#remove cruft
rm t_area_bdy.prn t_area_bdy_exe
g.remove v=t_area_bdy,t_area_lab_bdy,t_area_line

# print results
v.db.select t_area_line2 | sort -n

# output:
#cat|name|cstln_mtr
#1|island group 1|15829.356619
#2|island group 2|19672.841857
#...
# success!

Hamish

Alle 11:51, martedì 04 ottobre 2005, ivan marchesini ha scritto:
> Dear users...
> I have a simple question.... I hope...
> I have a map composed of areas and centroids...
> each centroid is connected to a record in a postgres table...
> but the boundaries don't have connection with the database table
>
> using v.to.db is really simple to upload the area value to the table,
> but how can I do to upload the perimeter of the area???
>
> I have tried with the length option but v.to.db try to upload the length
> of the centroid that obviously is 0...
>
> thank you for your answer...
> ivan

-- 
Leonardo Lami
lami at faunalia.it            www.faunalia.it
Via Colombo 3 - 51010 Massa e Cozzile (PT), Italy   Tel: (+39)349-1310164
GPG key @: hkp://wwwkeys.pgp.net http://www.pgp.net/wwwkeys.html
https://www.biglumber.com




More information about the grass-user mailing list