城市规划应用场景:人的空间密度分布、城市道路网人流及车流量分布等
系统环境:Window7 64位
工具:系统中已经具备Java虚拟机(jdk)
与Java虚拟机位数匹配的Processing
Processing下载地址:https://www.processing.org/
开始下载Processing:
准备一份格网点或轨迹点数据,数据格式为三元组(lat,lon,value)
每一行代表一个格网店或轨迹点,用分隔符隔开
打开Processing软件
另存工程
找到创建Processing工程的文件夹,在保存目录下会出现*.pde的文件
在工程目录下新建一个data文件夹,将准备好的数据放到data文件夹下
编写代码
import java.util.Iterator;
import processing.pdf.*;
BufferedReader readerstr;
BufferedReader reader;
color from=color(76,164,250);
color to=color(255,28,28);
color co;
String linestr;
String linec;
int count=0;
String line;
float p1_x,p2_x,p3_x,p4_x,p1_y,p3_y,p2_y;
float showp1_x,showp2_x,showp3_x,showp4_x,showp1_y,showp2_y,showp3_y,showpw,showph_1,showph_2,showph_3;
float pwith=11.25,pheight_1=10.0091165,pheight_2=10.7646455,pheight_3=11.1784;
float tranx=0,trany=0,s=1,rotx=0;
ArrayList dis=new ArrayList();
void setup(){
// size(displayWidth,displayHeight,P3D);
size(1400,950,P3D);
frameRate(60);
background(25);
// noStroke();
smooth();
reader=createReader("popdistribution.txt");
p1_x=112.5;
p2_x=123.75 ;
p3_x=135.0;
p4_x=146.25;
p1_y=31.952162;
p2_y=21.9430455;
p3_y=11.1784;
showp1_x=map(p1_x,72,157.8,0,width);
showp2_x=map(p2_x,72,157.8,0,width);
showp3_x=map(p3_x,72,157.8,0,width);
showp4_x=map(p4_x,72,157.8,0,width);
showpw=width/(145.8-60)*pwith;
showp1_y=map(p1_y,5,55,height,0);
showp2_y=map(p2_y,5,55,height,0);
showp3_y=map(p3_y,5,55,height,0);
showph_1=height/50.0*pheight_1;
showph_2=height/50.0*pheight_2;
showph_3=height/50.0*pheight_3;
try{
while((linestr=reader.readLine())!=null){
C c=new C(linestr);
dis.add(c);
}
}
catch (IOException e) {
e.printStackTrace();
linestr = null;
}
println(dis.get(25553).x);
println(dis.size());
noStroke();
fill(12,132,56,255);
color color1,color2,color3,color4,color5,color6;
color6=color(255, 0, 0);
color5=color(255, 255, 0);
color4=color(0, 255, 0);
color3=color(0, 255, 255);
color2=color(0, 0, 255);
color1=color(255, 0, 255);
for(int i=0;i0){
if(dis.get(i).value<=6)
co=lerpColor(color1,color2,map(dis.get(i).value,0,6,0,1));
else if(dis.get(i).value>6&&dis.get(i).value<=9)
co=lerpColor(color2,color3,map(dis.get(i).value,6,9,0,1));
else if(dis.get(i).value>9&&dis.get(i).value<=12)
co=lerpColor(color3,color4,map(dis.get(i).value,9,12,0,1));
else if(dis.get(i).value>12&&dis.get(i).value<=15)
co=lerpColor(color4,color5,map(dis.get(i).value,12,15,0,1));
else if(dis.get(i).value>15&&dis.get(i).value<=18)
co=lerpColor(color5,color6,map(dis.get(i).value,15,18,0,1));
else co=color6;
fill(co);
ellipse(dis.get(i).x ,dis.get(i).y, 1.5,1.5);
}
}
save("diagonal.png");
}
void draw(){
}
class C{
float x,y,value;
C(){
x=y=value=0;
}
C(String s){
String[] ss=split(s,'\t');
x=map((float(ss[0])),62,147.8,0,width);
y=map((float(ss[1])),9,57,height,0);
value=log(float(ss[2]))/log(2);
}
}
运行代码:
结果:
练习数据下载地址:https://pan.baidu.com/s/1X9dPMg1p9_6VdtdQRV3-AA 密码:0mkp