1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
function [] = createjson (inputfile, outputdir)
tic
imp=load(inputfile,'input');
cd('mat2html')
mkdir(outputdir)
cd('lib_init')
copyfile('page.html', strcat('..', filesep, outputdir))
cd('..')
cd(outputdir)
filename='buildings.js';
XY=imp.input.XY;
data=imp.input.data;
dlmwrite(filename, ['var buildings={"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG:2154"}},"type":"FeatureCollection","features":['], 'delimiter', '')
for i=1:numel(XY);
x=XY{i}(:,1);
y=XY{i}(:,2);
dlmwrite(filename, ['{"type":"Feature","geometry":{"type":"Polygon","coordinates":['], '-append', 'delimiter', '')
s = '[';
for j=1:numel(x);
if (~isnan(x(j)) & ~isnan(y(j)));
s = strcat(s, strcat('[', num2str(round(x(j), 1)), ',', num2str(round(y(j), 1)), '],'));
end
end
s = strcat(s(1:end-1), ']');
dlmwrite(filename, [s,']},"properties":{"solar":', num2str(data(i)), '}},'], '-append', 'delimiter', '')
end
dlmwrite(filename, [']}'], '-append', 'delimiter', '')
dlmwrite(filename, ['var min_val=', num2str(min(data))], '-append', 'delimiter', '')
dlmwrite(filename, ['var max_val=', num2str(max(data))], '-append', 'delimiter', '')
toc
t = toc;
cd('../..')
end |
Partager