createCSMeas static method

CoordinateSequence createCSMeas(
  1. CoordinateSequenceFactory csFactory,
  2. int size,
  3. int dimension,
  4. int measures,
)

Creates a {@link CoordinateSequence} using the provided factory confirming the provided size and dimension are respected.

If the requested dimension is larger than the CoordinateSequence implementation can provide, then a sequence of maximum possible dimension should be created. An error should not be thrown.

This method is functionally identical to calling csFactory.create(size,dim) - it contains additional logic to work around a limitation on the commonly used CoordinateArraySequenceFactory.

@param size the number of coordinates in the sequence @param dimension the dimension of the coordinates in the sequence @param measures the measures of the coordinates in the sequence

Implementation

static CoordinateSequence createCSMeas(CoordinateSequenceFactory csFactory,
    int size, int dimension, int measures) {
  CoordinateSequence cs;
  if (csFactory is CoordinateArraySequenceFactory && dimension == 1) {
    // work around JTS 1.14 CoordinateArraySequenceFactory regression ignoring provided
    // dimension
    cs = CoordinateArraySequence.fromSizeDimensionMeasures(
        size, dimension, measures);
  } else {
    cs = csFactory.createSizeDimMeas(size, dimension, measures);
  }
  if (cs.getDimension() != dimension) {
    // illegal state error, try and fix
    throw StateError(
        "Unable to use $csFactory to produce CoordinateSequence with dimension $dimension");
  }
  return cs;
}