我在尝试从CSV文件中绘制一些坐标时遇到了一些麻烦。我正在使用纬度和经度,然后我使用Web墨卡托(https://en.wikipedia.org/wiki/Web_Mercator#Formulas)转换它们,之后我将使用最小值和最大值并使用map()函数将它们映射到之间的值0和500.但是,我收到以下错误:
总行数:6606
maxLat = 198987.05; minLat = 198986.94; maxLong = 110837.664; minLong = 110836.695 拉特&在映射之前很久:198986.27; 110840.68 拉特& map()之后很久:-6142.857; 4112.9033 拉特&在norm()之后很久:-6.142857; 4.112903
地图(NaN,198986.94,198987.05,0,500)调用,返回NaN(不是数字)
地图(NaN,110836.695,110837.664,0,500)被叫,返回NaN(不是数字)
我很感激如何解决错误或代码改进的任何建议。 先感谢您。 代码本身:
import java.util.Collections;
Table csvFile;
ArrayList<Float>times = new ArrayList<Float>();
ArrayList<Float>latitude = new ArrayList<Float>();
ArrayList<Float>longitude = new ArrayList<Float>();
ArrayList<Float>lap = new ArrayList<Float>();
ArrayList<Float>latitudeCal = new ArrayList<Float>();
ArrayList<Float>longitudeCal = new ArrayList<Float>();
float maxLat = 0;
float maxLong = 0;
float minLat = 0;
float minLong = 0;
void setup() {
size(600, 800);
csvFile = loadTable("RRData.csv", "header");
int totalRows = csvFile.getRowCount();
println("total number of rows: " + totalRows);
for (TableRow row : csvFile.rows()) {
times.add(row.getFloat("Time"));
latitude.add(normLat(row.getFloat("Latitude")));
longitude.add(normLon(row.getFloat("Longitude")));
}
maxLat = latitude.get(0);
maxLong = longitude.get(0);
maxLat = latitude.get(0);
maxLong = longitude.get(0);
// Finding Max Values
for (int i = 1; i < latitude.size() - 1; i++) {
maxLat = max(maxLat, latitude.get(i));
maxLong = max(maxLong, longitude.get(i));
minLat = min(minLat, latitude.get(i));
minLong = min(minLong, longitude.get(i));
}
println("maxLat = " + maxLat + "; minLat = " + minLat + " ; maxLong = " + maxLong + "; minLong = " + minLong);
println("lat & long before mapping: " + latitude.get(0) + " ; " + longitude.get(0));
println("lat & long after map(): " + map(latitude.get(0), minLat, maxLat, 0, 1000) + " ; " + map(longitude.get(0), minLong, maxLong, 0, 1000)); // map() doesn't worked as intended
//Try Normalising
println("lat & long after norm(): " + norm(latitude.get(0), minLat, maxLat) + " ; " + norm(longitude.get(0), minLong, maxLong));
// Mapping
for (int i = 0; i < latitude.size() - 1; i++) {
float num = latitude.get(i);
float num2 = longitude.get(i);
//println(num);
//println(num2);
latitudeCal.add(map(num, minLat, maxLat, 0, 500));
longitudeCal.add(map(num2, minLong, maxLong, 0, 500));
}
}
float normLon(float lon) {
lon = radians(lon);
float a = (256 / PI) * pow(2, 10);
float b = lon + PI;
return a * b;
}
float normLat(float lat) {
lat = radians(lat);
float a = (256 / PI) * pow(2, 10);
float b = tan(PI / 4 + lat / 2);
float c = PI - log(b);
return a * c;
}
void draw() {
background(51);
for (int i = 0; i < times.size() - 1; i++) {
noFill();
ellipse(latitude.get(i), longitude.get(i), 20, 20);
}
}