[GRASSLIST:5862] Re: Questions on v.digit

Paul Kelly paul-grass at stjohnspoint.co.uk
Tue Mar 25 10:47:50 EST 2003


Hello

On Mon, 24 Mar 2003, Kurt Springs wrote:

> Last question:  I will be receiving contour maps made by the Irish ordinance
> survey in .dxf form from my professor.  The contours should have been
> labelled by the OS.  I expect that v.in.dxf should do the job.  Are there
> any surprises that I should watch for?

I have used v.in.dxf and v.in.dxf3d to input contour maps supplied by the
Ordnance Survey of Northern Ireland; I don't know if OSi use the same format
(probably not!). But the problem I found with v.in.dxf3d was it attached
the attributes of each line in the dxf file as an attribute of each line in
GRASS. However in GRASS the attributes are all supposed to be integer
numbers greater than 0 and for areas near the sea, where the attribute of
the HWMMT line was 0, v.support just silently deleted all these lines.

If you don't mind going down into the files in the GRASS database, the
solution I found was to use a Perl script to move the attributes
from the attribute file (dig_att directory) to a new categories file
(dig_cats directory), and replace the dig_att file with a new one
containing only integer numbers greater than 0.

I have attached the script below but it is a bit crude as I only had to
use it a few times. It is important to run it after running v.in.dxf and
v.in.dxf3d but before running v.support. It must be run from the dig_att
directory, with the name of the vector file as its only command-line
argument.

As far as I can remember (this was at least a year ago) v.in.dxf3d has a
few bugs, documentation and otherwise. From my notes I see that 'lines='
is not optional and must be supplied, and 'prefix=' is not an option here
so you may have to rename the dig_att file after running v.in.dxf3d if
you used the prefix option with v.in.dxf.

Paul
-------------- next part --------------
#!/usr/local/bin/perl
$filename = $ARGV[0]; # Run from dig_att directory; provide filename on cmd line
open(FILE, $filename) || die($filename." not found.\n");
system "cp $filename $filename.orig";  # Save a copy as we're going to overwrite this
@atts = <FILE>;  # Read in the whole file into atts array (one line per array element)
close(FILE);
$size=@atts;     # Find the total number of attribute entries (needed for cats file)
open(FILE, ">../dig_cats/".$filename);  # Open a file of same name in cats directory
print(FILE "# ".$size." categories\n\n\n0.00 0.00 0.00 0.00\n"); # Standard header
open(FILE1, ">".$filename); # Ready to overwrite the old attribute file
$catno=0;    # Increases by one for every line in att file: unique number
foreach $att(@atts)   # For each line in attribute file
{
   chomp($att);       # Remove new line character
   @data=split(/\s+/, $att, 4);  # Split into A/L, easting, northing, description
   $linetype=$data[0]." ".$data[1]." ".$data[2]; # A/L, east, north stay together
   $category=$data[3];  # Separate out the category description as we're moving it
   if ($category ne "")           # Not a null value
   {
     $catno++;
     print(FILE1 $linetype." ".$catno."\n"); # New attributes file contains unique cat no
     print(FILE $catno.":".$category."\n");  # Cats file contains unique catno + description
   }
}
close(FILE);
close(FILE1);


More information about the grass-user mailing list