Gianpaolo Coro 2015-10-30 11:44:51 +00:00
parent 87f0d0e9af
commit 0f462ff9e3
1 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,105 @@
package org.gcube.dataanalysis.geo.utils;
public class GridCWPConverter {
public static void main(String[] args) {
GridCWPConverter gridder = new GridCWPConverter();
gridder.gridCodeToPair("5206064");
System.out.println(gridder.outlon+","+gridder.outlat+","+gridder.gridresolution);
}
public float outlon;
public float outlat;
public int gridresolution;
public void gridCodeToPair (String grid){
char resolution = grid.charAt(0);
int quadrant = Integer.parseInt(""+grid.charAt(1));
float lat = Float.parseFloat(grid.substring(2,4));
float lon = Float.parseFloat(grid.substring(4));
int Xr = getResolutionX(resolution);
// int Yr = getResolutionY(resolution);
gridresolution = Xr;
float latAdj = adjustLat(lat, quadrant);
float lonAdj = adjustLon(lon, quadrant);
int resolutionY = getResolutionY(resolution);
int resolutionX = getResolutionX(resolution);
float centerLat = getCenterLat(latAdj, resolutionY, quadrant);
float centerLon = getCenterLon(lonAdj, resolutionX, quadrant);
// System.out.println("Xr:"+Xr+" Yr:"+Yr+" Lat:"+lat+" Lon:"+lon+" LatAdj:"+latAdj+" LonAdj:"+lonAdj+" Q:"+quadrant+" centLon:"+centerLon+" centLat:"+centerLat);
outlat = centerLat;
outlon = centerLon;
}
public float getCenterLat(float lat, int resolutionY, int quadrant){
float halfres = (float) resolutionY/2f;
if (quadrant == 1 || quadrant == 4)
return lat+halfres;
else
return lat-halfres;
}
public float getCenterLon(float lon, int resolutionX, int quadrant){
float halfres = (float) resolutionX/2f;
if (quadrant == 1 || quadrant == 2)
return lon+halfres;
else
return lon-halfres;
}
public float adjustLat(float lat,int quadrant){
if (quadrant==1 || quadrant==4)
return lat;
else
return -1*lat;
}
public float adjustLon(float lon,int quadrant){
if (quadrant==1 || quadrant==2)
return lon;
else
return -1*lon;
}
public int getResolutionY(char token){
if (token == '5')
return 1;
else if (token == '6')
return 5;
else if (token == '1')
return 5;
else if (token == '2')
return 10;
else if (token == '3')
return 10;
else if (token == '4')
return 20;
else
return -1;
}
public int getResolutionX(char token){
if (token == '5')
return 1;
else if (token == '6')
return 5;
else if (token == '1')
return 10;
else if (token == '2')
return 20;
else if (token == '3')
return 10;
else if (token == '4')
return 20;
else
return -1;
}
}