use of org.jdesktop.swingx.mapviewer.GeotoolsConverter in project hale by halestudio.
the class AreaCalc method checkEPSG.
/**
* Checks if GeoPosition are in a metric system and if not convert them if
* necessary.
*
* @param pos List of {@link GeoPosition}
*
* @return List of {@link GeoPosition}
*/
public List<GeoPosition> checkEPSG(List<GeoPosition> pos) {
// list is empty
if (pos.size() == 0) {
return pos;
}
//
int epsg = pos.get(0).getEpsgCode();
// Worldmercator
int FALLBACK_EPSG = 3395;
// WGS84
FALLBACK_EPSG = 4326;
try {
CoordinateSystem cs = CRS.decode("EPSG:" + epsg).getCoordinateSystem();
for (int i = 0; epsg != FALLBACK_EPSG && i < cs.getDimension(); i++) {
CoordinateSystemAxis axis = cs.getAxis(i);
try {
Unit<Length> unit = axis.getUnit().asType(Length.class);
if (!unit.toString().equals("m")) {
// $NON-NLS-1$
// not metric
epsg = FALLBACK_EPSG;
}
} catch (ClassCastException e) {
// no length unit
epsg = FALLBACK_EPSG;
}
}
} catch (Exception e) {
e.printStackTrace();
}
// convert all coordinates
try {
GeotoolsConverter g = (GeotoolsConverter) GeotoolsConverter.getInstance();
pos = g.convertAll(pos, epsg);
} catch (IllegalGeoPositionException e1) {
e1.printStackTrace();
}
return pos;
}
Aggregations