floc in hexa by matmul
[wrf-fire-matlab.git] / cycling / perim2mat.m
blob8dcf2916f6d47bed6db7570ac9a462ec46ede18c
1 % make .mat files from a kml for use in data assimilation
2 % requires mapping toolbox and the kml2struct.m function
4 kmlFile = '../cycling_data/TIFs/doc.kml';
5 a = kml2struct(kmlFile);
6 %load('perim_struct.mat');
8 %look at the kml file
9 p_count = 0;
10 %hold on
12 %%%%%%% start 13 for special point %%%%%%%%
13 % number of points in grid to use
14 n = 100;
15 for i = 13:length(a)
16     i, a(i)
17     if strcmp(a(i).Geometry,'Polygon')
18         p_count = p_count + 1;        
19         %i,a(i)
20         
21         %set decimate to an  postive integer to use just a subset of points
22         %  in perimeter
23         decimate = 1;
24         lats = a(i).Lat(1:decimate:end);
25         lons = a(i).Lon(1:decimate:end);
27         %create regularly spaced data
28         dx = (a(i).BoundingBox(2,1)-a(i).BoundingBox(1,1))/n;
29         dy = (a(i).BoundingBox(1,2)-a(i).BoundingBox(2,2))/n;
30         
31         xa = linspace(a(i).BoundingBox(1,1),a(i).BoundingBox(2,1),n);
32         ya = linspace(a(i).BoundingBox(2,2),a(i).BoundingBox(1,2),n);
33         
34         %find data inside of perimeter
35         [x,y] = meshgrid(xa,ya);
36         x = x(:);
37         y = y(:);
38         [in,on] = inpolygon(x,y,lons,lats);
39         fires = logical(in+on);
40         data = reshape(fires,n,n);
41         %make all high confidence fires
42         data = uint8(9.0*data);
43         a(i).data = data;
44         geotransform = [ a(i).BoundingBox(1,1) dx 0  a(i).BoundingBox(2,2) 0 dy];
45         a(i).geotransform = geotransform;
46         %save the file for use in data assimilation
47         %save(a(i).TIF_name,'data','geotransform');
48         %plot results
49         plot_on = 1;
50         if plot_on
51             figure
52             hold on
53             plot(lons,lats);
54             scatter(x,y);
55             scatter(x(fires),y(fires),'*','r');
56             title(a(i).Name);
57             plot(lons,lats)
58             hold off
59             %figure,mesh(data)
60         end %if plot_on
61         
62     end
63 end %for
65 %save perim_struct.mat a
66 fprintf('There were %i perimeters found in the data set\n',p_count)