Last active
August 29, 2015 14:03
-
-
Save JorgeGT/22830f647f3895837ba3 to your computer and use it in GitHub Desktop.
Testing Valencia open data =)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Valencia Point by Point | |
% Copyright (C) 2014 Jorge Garcia Tiscar | |
% | |
% This program is free software: you can redistribute it and/or modify | |
% it under the terms of the GNU General Public License as published by | |
% the Free Software Foundation; either version 3 of the License, or | |
% (at your option) any later version (see LICENSE). | |
%% Initialize | |
clear all | |
close all | |
clc | |
% Parameters | |
latMin = 39.4368; | |
pointSize = 1.5; | |
textColor = [0.1 0.1 0.1]; | |
coords = [-0.4201 -0.3202 39.4326 39.5076]; % Valencia area | |
url = 'http://mapas.valencia.es/lanzadera/opendata'; | |
datos = { | |
'Cia_imbornales' | |
'arboles' | |
'Res_papeleras' | |
'res_contenedor' | |
'Hidrantes' | |
}; | |
colores = [ | |
[0.5 0.5 0.5] | |
[30 100 50]./255 | |
[0 0 1] | |
[250 150 100]./255 | |
[1 0 0] | |
]; | |
% Figure | |
figure('DefaultTextFontName', 'Myriad Pro', ... | |
'DefaultTextFontSize', 5.5,... | |
'DefaultTextColor', textColor,... | |
'DefaultTextUnits','normalized',... | |
'Position', [1400, 0, 700, 500],... | |
'Visible','off') | |
% Download, extract, and/or read and plot points | |
hold on | |
for i = 1:length(datos) | |
if ~exist([datos{i} '.shp'],'file') % If not cached, download | |
disp(['Downloading ' url '/' datos{i} '/SHAPE']) | |
urlwrite([url '/' datos{i} '/SHAPE'],'temp.zip'); | |
unzip temp.zip | |
delete temp.zip | |
else | |
disp(['Reading existing ' datos{i} '.shp']) | |
end | |
data = shaperead([datos{i} '.shp']); | |
long = [data.X]; | |
lat = [data.Y]; | |
plot(long(lat>latMin),lat(lat>latMin),'.','MarkerSize',pointSize,'Color',colores(i,:)) | |
end | |
% Format | |
axis equal | |
axis(coords) | |
axis on | |
box on | |
% Add legend | |
l = legend({ | |
'Drain' | |
'Tree' | |
'Bin' | |
'Dumpster' | |
'Hydrant' | |
},'location','southwest'); | |
% Adjust legend (some cosmetic tricks!) | |
legend boxoff | |
s = get(legend); | |
s1 = s.Children; | |
s2 = findobj(s1,{'type','line'}); | |
s3 = findobj(s1,{'type','text'}); | |
for m = 1:length(s2) | |
set(s2(m),'markersize',12) | |
try | |
set(s3(m),'fontsize',8); | |
set(s3(m),'position',get(s3(m),'position')-[0.1 0 0]); | |
end %#ok<*TRYNC> | |
end | |
set(l,'position',s.Position-[0.03 0.03 0 0]); | |
set(l,'PlotBoxAspectRatioMode','manual'); | |
set(l,'PlotBoxAspectRatio',[1 0.5 1]); | |
% Add title | |
set(gcf,'DefaultTextHorizontalAlignment', 'right') | |
text(0.96,0.98,'Valencia','FontSize',18,'VerticalAlignment','top') | |
% Add subtitles | |
text(0.94,0.88,{ | |
'Point by point' | |
},'FontSize',8) | |
% Add copyright | |
text(0.99,0.01,{ | |
'CC-BY 4.0 @JorgeGT - Open data by www.valencia.es/datosabiertos' | |
},'VerticalAlignment','bottom','FontSize',5) %#ok<*UNRCH> | |
% Export | |
set(gca,'Color','w',... | |
'XColor',textColor,... | |
'YColor',textColor,... | |
'ZColor',textColor,... | |
'Xtick',[],'Ytick',[]) | |
export_fig('ValenciaPuntosEN','-png','-r300') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So...
This is the result of the sample script above: