[GRASSLIST:4950] Re: v.to.rast with area fills
H. Bowman
ihatejunkyabastards at yahoo.com
Thu Nov 14 11:13:37 EST 2002
I recently wrote a little matlab script to do just this. If you don't have
matlab, the GPL'd octave or scilab should run it, or spend 5 minutes to
get it working in C / bash ...
%% ga_vect2poly.m Hamish Bowman, Nov 11, 2002
%
% Convert GRASS ASCII vector files to GRASS poly files for use with
r.in.poly.
%
% v.out.ascii, ga_vect2poly.m, r.in.poly
%
format long g
FileName = '~/grass5_data/milford/bathy/dig_ascii/milf_island_poly'
OutName = [FileName '.poly'];
fp1 = fopen(FileName, 'r');
fp2 = fopen(OutName, 'w');
%% get past header
for i = 1:14
disp(fgetl(fp1))
end
n=0; % island number
while(length(ferror(fp1)) == 0) %% ie not EOF
n = n+1;
buff = fgetl(fp1);
if(buff(1) == 'A')
numVerts = sscanf(buff, 'A %d');
disp(['Island ' num2str(n) ' has ' num2str(numVerts) '
verts.'])
island = fscanf(fp1, '%f %f\n', [2 numVerts])'; % 2
columns, else
disp('eh?? that''s not right:')
disp(buff)
end
fprintf(fp2, 'A\n');
for i = 1:length(island)
%
note vect ascii is northing,easting
fprintf(fp2, ' %.3f %.3f\n', island(i,2), island(i,1));
end
fprintf(fp2, '= %d\n', n);
end
fclose(fp1);
fclose(fp2);
More information about the grass-user
mailing list