final double miny,
final double maxx,
final double maxy,
final Unit unit) {
final BasicFactories commonFactory = BasicFactories.getDefault();
final GeometryFactory geometryFactory = commonFactory.getGeometryFactory(crs);
final CoordinateSystem cs = crs.getCoordinateSystem();
final int xIndex = getDirectedAxisIndex(cs, AxisDirection.EAST);
final Unit xUnit = getDirectedAxisUnit(cs, AxisDirection.EAST);
final int yIndex = getDirectedAxisIndex(cs, AxisDirection.NORTH);
final Unit yUnit = getDirectedAxisUnit(cs, AxisDirection.NORTH);
// HACK(jdc): need to determine the order of the axes...
/*int[] indices = CSUtils.getDirectedAxisIndices(
crs.getCoordinateSystem(),
new AxisDirection[] { AxisDirection.EAST, AxisDirection.NORTH });*/
//edited to use javax.measure.unit.Convertor
UnitConverter xConverter = xUnit.getConverterTo(unit);
UnitConverter yConverter = yUnit.getConverterTo(unit);
double[] lowerOrdinates = new double[crs.getCoordinateSystem().getDimension()];
lowerOrdinates[xIndex] = xConverter.convert(minx);
lowerOrdinates[yIndex] = yConverter.convert(miny);
/*for (int i = 0; i < lowerOrdinates.length; i++) {
// the east or x ordinate
if (i == indices[0]) {
lowerOrdinates[i] = minx;
// the north or y ordinate
} else if (i == indices[1]) {
lowerOrdinates[i] = miny;
} else {
lowerOrdinates[i] = 0;
}
}*/
double[] upperOrdinates = new double[crs.getCoordinateSystem().getDimension()];
upperOrdinates[xIndex] = xConverter.convert(maxx);
upperOrdinates[yIndex] = yConverter.convert(maxy);
/*for (int i = 0; i < upperOrdinates.length; i++) {
// the east or x ordinate
if (i == indices[0]) {
upperOrdinates[i] = maxx;
// the north or y ordinate
} else if (i == indices[1]) {
upperOrdinates[i] = maxy;
} else {
upperOrdinates[i] = 0;
}
}*/
final DirectPosition lowerCorner = geometryFactory.createDirectPosition(lowerOrdinates);
final DirectPosition upperCorner = geometryFactory.createDirectPosition(upperOrdinates);
return geometryFactory.createEnvelope(lowerCorner, upperCorner);
}