獲取WRF文件NETCDF中的網格經緯度

String location = "D:/data/wrfout1/wrfout_d02_2020-12-10_00_00_00";
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(location);  
NetcdfDataset gid = gds.getNetcdfDataset(); 
GridCoordSystem gcs =  gds.getGrids().get(0).getCoordinateSystem();
ProjectionImpl proj = gcs.getProjection();
Variable vr = gid.findVariable("x");
Variable vr2 = gid.findVariable("y");
Array data1 = vr.read();
Array data2 = vr2.read();

int[] shape = data1.getShape();
int[] shape2 = data2.getShape();
Index index = data1.getIndex();
Index index2 = data2.getIndex();
double dval;
double dval2; 
for (int j=0; j<shape2[0]; j++)
  for (int i=0; i<shape[0]; i++){
    dval = data1.getInt(index.set(i));
    dval2 = data2.getInt(index2.set(j));
    System.out.println(dval + " " + dval2 + " " + proj.projToLatLon(dval, dval2).getLatitude() + "  " + proj.projToLatLon(dval, dval2).getLongitude() );
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章