code: private CoordinateSequence restoreDim4(CoordinateSequence cs, Map<Coordinate, Double> map) {
          CoordinateSequence seq = new PackedCoordinateSequenceFactory(DOUBLE, 4).create(cs.size(), 4);
          for (int i = 0; i < cs.size(); i++) {
              seq.setOrdinate(i, 0, cs.getOrdinate(i, 0));
              seq.setOrdinate(i, 1, cs.getOrdinate(i, 1));
              seq.setOrdinate(i, 2, cs.getOrdinate(i, 2));
              Double d = map.get(cs.getCoordinate(i));
              seq.setOrdinate(i, 3, d == null ? Double.NaN : d);
          }
          return seq;
      }
docs: Use map to restore M values on the coordinate array