package kune;
import java.io.*;
public class pro {
int datanumber,number;
String[] data=new String[50000];
double[] lat=new double[60000];
double[] lon=new double[60000];
double[] latx=new double[60000];
double[] lonx=new double[60000];
String[] code=new String[50000];
String[] delta=new String[50000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readx("line.csv");
int s;
for(s=2;s<datanumber+1;s++){
String[] x=data[s].split(",");
lat[s-1]=num_double(x[3]);
lon[s-1]=num_double(x[4]);
}
number=datanumber-1;
readx("post.csv");
for(s=2;s<datanumber+1;s++){
String[] x=data[s].split(",");
latx[s-1]=num_double(x[1]);
lonx[s-1]=num_double(x[0]);
code[s-1]=x[3];
}
datanumber=datanumber-1;
int sx;
for(s=1;s<number+1;s++){
double mind=999999;
int sxs=0;
for(sx=1;sx<datanumber+1;sx++){
double d1=2.25*(lon[s]-lonx[sx])*(lon[s]-lonx[sx]);
d1=d1+(lat[s]-latx[sx])*(lat[s]-latx[sx]);
if(d1<mind)sxs=sx;
if(d1<mind)mind=d1;
}
delta[s]=code[sxs];
System.out.println(code[sxs]);
}
readx("line.csv");
writecsv("ren.txt");
}
double num_double(String str){
double nx;
nx=0;
try{
nx=Double.parseDouble(str);
}catch (Exception e) {}
return nx;
}
void writecsv(String file){
int s;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println(data[1]);
for(s=2;s<datanumber+1;s++){
pw.println(data[s]+","+delta[s-1]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2017年04月02日 03:01