final double origX = envelope.getLowerCorner().getOrdinate(0)+resX/2;
final double origY = envelope.getUpperCorner().getOrdinate(1)+resY/2;
// create offset point
final PointType origin = Gml4wcsFactory.eINSTANCE.createPointType();
final DirectPositionType dp = Gml4wcsFactory.eINSTANCE.createDirectPositionType();
origin.setPos(dp);
origin.setSrsName(crsName);
// create resolutions vector
final VectorType resolutionVector = Gml4wcsFactory.eINSTANCE.createVectorType();
//
// Third dimension management
//
final Object rz = kvp.get("resz");
if (rz != null) {
// afabiani: we consider 2D grdis only
throw new WcsException("3D grids are not supported.", InvalidParameterValue, "resz");
// // eventual depth
// final double resZ = Double.parseDouble((String) rz);
// // check that the envelope is 3D or throw an error
// if (bbox.getDimension() != 3)
// throw new WcsException("Found ResZ but envelope is of dimension "
// + bbox.getDimension(), InvalidParameterValue, "");
// final double origZ = bbox.getLowerCorner().getOrdinate(2);
//
// // 3D grid
// grid.setDimension(BigInteger.valueOf(3));
// // set the origin position
// dp.setDimension(grid.getDimension());
// dp.setValue(Arrays.asList(origX, origY, origZ));
// grid.setOrigin(origin);
//
// // set the resolution vector
// resolutionVector.setDimension(grid.getDimension());
// resolutionVector.setValue(Arrays.asList(resX, resY, resZ));
// grid.getOffsetVector().add(resolutionVector);
} else {
// 2d grid
grid.setDimension(BigInteger.valueOf(2));
// set the origin position
dp.setDimension(grid.getDimension());
dp.setValue(Arrays.asList(origX, origY));
grid.setOrigin(origin);
// set the resolution vector
resolutionVector.setDimension(grid.getDimension());
resolutionVector.setValue(Arrays.asList(resX, resY));