connectivity matrix from vect file
Dave Gerdes
dpgerdes at zorro.cecer.army.mil
Wed Apr 15 14:51:04 EDT 1992
> Date: Tue, 14 Apr 92 20:14:59 -0500
> From: mccauley at ecn.purdue.edu (Darrell McCauley)
> Message-Id: <9204150114.AA02865 at clover.ecn.purdue.edu>
> Sender: lists-owner at amber.cecer.army.mil
> Reply-To: grassp-list at amber.cecer.army.mil
> Precedence: Bulk
> To: grassp-list at amber.cecer.army.mil
> Subject: connectivity matrix from vect file
>
>
> I want to form a connectivity matrix from a vector file:
> an N x N symmetric matrix called C with non-zero entries
> in C(i,j) when the area labeled with category i shares a border
> with the area labeled with category j (assuming all areas
> have unique labels). "Connected" means they share a line, not
> just a node.
>
> Looking over the structs for topology files, I don't believe that
> this information is explicitly stored (correct me if I'm wrong).
> Before I get too carried away, has anyone ever done this?
>
> Seems simple: for (i=0;i<Plus_head.n_areas;++i)
> for (j=0;j<P_area.n_lines;++j) {
> /* must cross line j, returns adjacent category */
> k=find_area_which_shares_line(i,j);
> c[cat_of_area(i)][cat_of_area(k)]++;
> }
>
> If anyone knows a easy way to do this or can suggest
> the best src program and/or library functions to use
> as a starting point, I would be grateful for a short
> reply in private email.
>
> Thanks,
> --Darrell
>
>
First off, in GRASS you index the line and areas from 1 to N, not 1 to N-1.
The key is that lines store which areas are to their left and to their right.
If you loop by areas as above, then you will get twice the number
of hits as you want, since each line would be tested twice.
The code you want is something like:
struct Map_info *Map; /* returned from Vect_open_old() */
/* level must be >= 2 */
P_LINE *Line;
for (i=1 ; i <= Map.n_lines ; ++i) /* for each line */
{
Line = &(Plus_head.Line[i]); /* just set pointer */
/* must cross line j, returns adjacent category */
if (Line->left && Line->right) /* if it sits between 2 areas */
{ /* then get the attributes and update matrix */
c[V2_area_att (Map, Line->left)][V2_area_att (Map, Line->right)]++;
}
}
--
Dave Gerdes
US Army Construction Engineering Research Lab
Spatial Analysis & Systems Team
dpgerdes at cerl.cecer.army.mil
(217) 352-6511 x591
More information about the grass-dev
mailing list