现在,我正在一个项目中,尝试可视化纽约市的互联网覆盖范围。我已经下载了fcc的csv,其中详细介绍了美国的互联网覆盖范围,并使用java对其进行了解析,以获取仅与纽约有关的所有数据。我仅通过选择包含纽约5个县(五个行政区)的正确普查代码的数据行来做到这一点。这是问题所在。 fcc的csv仅有的地理链接数据是人口普查代码,现在,我在将数据链接到地图上的地理位置时遇到了麻烦。我有一个geojson文件,其中包含与nyc中每个人口普查代码一起提供的地理数据,但是我不知道如何在Java中解析和编辑geojson文件。这是我拥有的geojson的格式:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 0,
"properties": {
"OBJECTID": 2038,
"STATEFP": "36",
"COUNTYFP": "081",
"TRACTCE": "014000",
"BLKGRPCE": "1",
"GEOID": "360810140001",
"NAMELSAD": "Block Group 1",
"MTFCC": "G5030",
"FUNCSTAT": "S",
"ALAND": 113131,
"AWATER": 0,
"INTPTLAT": "+40.7030341",
"INTPTLON": "-073.8279064",
"geo_id": "15000US360810140001",
"OBJECTID_1": 10466,
"GEOID_1": "15000US360810140001",
"SHAPE_Leng": 0.02086447918,
"SHAPE_Area": 0.00001205464
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-73.82266,
40.703585
],
[
-73.83152,
40.70139
],
[
-73.83213,
40.702794
],
[
-73.82576,
40.704428
],
[
-73.82246,
40.703656
],
[
-73.82266,
40.703585
]
]
]
}
},
我想象的方法是选择第一个geojson对象,然后使用该代码搜索csv,或者选择第一个csv行,然后在我的geojson中搜索相同的普查代码。这样显然是效率低下的。是一种更好的解决方案,以某种方式根据普查代码的数值对csv进行排序,然后从geojson开始读取吗?如果csv被订购,我可以编写一个二进制搜索算法来做到这一点。
总结一下:我需要基于一列的数值排序csv的帮助,以及有关读取和编辑geojson文件的帮助。 我将不胜感激。
这是我试图用来配对值的代码(我已经将geojson转换为csv,但是我发现当从csv转换为geojson时,我发现没有在线代码可以正常工作。) >
public static void main(String args[]) throws FileNotFoundException{
// Construct a BufferedReader object from the input file
BufferedReader r = new BufferedReader(new FileReader("newyorkcitydistilled.csv"));
BufferedReader cs = new BufferedReader(new FileReader("convertcsv.csv"));
String[] linedata;
String[] linedata2;
PrintWriter pw = new PrintWriter(new File("nycdistilledgeo2.csv"));
String line;
String line2;
int it = 0;
try{
//prime the geodata
//NOTE TO SELF!!! THE CSV FOR CONVERT NEETS TO BE REFORMATTED BECAUSE OF THE FIRST THREE COLUMNS
line2 = cs.readLine();
linedata2 = line2.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
while ((line = r.readLine()) != null) {
if (line.isEmpty()) {
break;}
it++;
if(it % 100 == 0)
System.out.println(it);
linedata = line.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
// System.out.print(line2);
//while the two lines being looked at dont fit the matching criteria, keep looking through the convertcsv
while((boroComp(linedata[9].substring(2,5),linedata2[4].substring(0,1)) && linedata[9].substring(5,15).equals(linedata2[4].substring(1,11))) == false){
line2 = cs.readLine();
try{
linedata2 = line2.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
// System.out.println(linedata2[4]);
}catch(NullPointerException e){
// System.out.println("caught");
break;
}
//somehow before it hits the last line of the csv, it needs to just say no match and move on
//need to restart the progress on readline for CS every time a correct comparison is made
}
// System.out.println("not broken");
//if it is true, add the new line in
// System.out.println(line2);
// System.out.println(linedata2[0] + "," + linedata2[1] + "," + linedata2[2] + "," + linedata2[5]);
// System.out.println(line + linedata2[0] + linedata2[1] + linedata2[2] + linedata2[5]);
pw.write(line + "," + linedata2[0] + "," + linedata2[1] + "," + linedata2[2] + "," + linedata2[5] + "\n");
//reset the buffered reader
cs.close();
cs = new BufferedReader(new FileReader("convertcsv.csv"));
//reprime the String
line2 = cs.readLine();
linedata2 = line2.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
}
r.close();
cs.close();
}
catch( IOException ioException ) {
System.out.println("Exception: "+ioException);
}
pw.flush();
}
}