org.geotools.geometry.jts.JTS.createCS()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中org.geotools.geometry.jts.JTS.createCS()方法的一些代码示例,展示了JTS.createCS()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTS.createCS()方法的具体详情如下:
包路径:org.geotools.geometry.jts.JTS
类名称:JTS
方法名:createCS

JTS.createCS介绍

[英]Creates a 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.
[中]使用提供的工厂创建坐标序列,确认所提供的尺寸和尺寸得到遵守。
如果请求的维度大于CoordinateSequence实现可以提供的维度,那么应该创建一个最大可能维度的序列。不应抛出错误。
此方法在功能上与调用csFactory相同。create(size,dim)-它包含额外的逻辑,以绕过常用CoordinaryArraySequenceFactory的限制。

代码示例

代码示例来源:origin: geotools/geotools

/**
 * Creates a {@link CoordinateSequence} using the provided factory confirming the provided size
 * and dimension are respected.
 *
 * <p>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.
 *
 * <p>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
 */
public static CoordinateSequence createCS(
    CoordinateSequenceFactory csFactory, int size, int dimension) {
  // the coordinates don't have measures
  return createCS(csFactory, size, dimension, 0);
}

代码示例来源:origin: geotools/geotools

@Override
public void newSubPart(final int numPoints) {
  this.subPartNo++;
  this.currPartNumPoints = numPoints;
  this.currPointNo = 0;
  final int dimension = 2;
  this.currCoordSeq =
      JTS.createCS(gf.getCoordinateSequenceFactory(), numPoints, dimension);
}

代码示例来源:origin: geotools/geotools

private CoordinateSequence readCoordinateSequence(int size) throws IOException {
  CoordinateSequence seq = JTS.createCS(csFactory, size, inputDimension, inputMeasures);
  int targetDim = seq.getDimension();
  if (targetDim > inputDimension) targetDim = inputDimension;
  for (int i = 0; i < size; i++) {
    readCoordinate();
    for (int j = 0; j < targetDim; j++) {
      seq.setOrdinate(i, j, ordValues[j]);
    }
  }
  return seq;
}

代码示例来源:origin: geotools/geotools

/** Converts the ordinate into a coordinate sequence */
public CoordinateSequence toCoordinateSequence(CoordinateSequenceFactory csfac) {
  CoordinateSequence cs = JTS.createCS(csfac, size(), 3);
  for (int i = 0; i <= curr; i++) {
    cs.setOrdinate(i, 0, ordinates[i * 2]);
    cs.setOrdinate(i, 1, ordinates[i * 2 + 1]);
  }
  return cs;
}

代码示例来源:origin: geotools/geotools

public Object read(ByteBuffer buffer, ShapeType type, boolean flatGeometry) {
  if (type == ShapeType.NULL) {
    return createNull();
  }
  int dimension = shapeType == ShapeType.POINTZ && !flatGeometry ? 3 : 2;
  CoordinateSequence cs =
      JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), 1, dimension);
  cs.setOrdinate(0, 0, buffer.getDouble());
  cs.setOrdinate(0, 1, buffer.getDouble());
  if (shapeType == ShapeType.POINTM) {
    buffer.getDouble();
  }
  if (dimension > 2) {
    cs.setOrdinate(0, 2, buffer.getDouble());
  }
  return geometryFactory.createPoint(cs);
}

代码示例来源:origin: geotools/geotools

cs = JTS.createCS(csFact, n, dim);

代码示例来源:origin: geotools/geotools

public Object read(ByteBuffer buffer, ShapeType type, boolean flatGeometry) {
  if (type == ShapeType.NULL) {
    return createNull();
  }
  // read bounding box (not needed)
  buffer.position(buffer.position() + 4 * 8);
  int numpoints = buffer.getInt();
  int dimensions = shapeType == shapeType.MULTIPOINTZ && !flatGeometry ? 3 : 2;
  CoordinateSequence cs =
      JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), numpoints, dimensions);
  DoubleBuffer dbuffer = buffer.asDoubleBuffer();
  double[] ordinates = new double[numpoints * 2];
  dbuffer.get(ordinates);
  for (int t = 0; t < numpoints; t++) {
    cs.setOrdinate(t, 0, ordinates[t * 2]);
    cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
  }
  if (dimensions > 2) {
    dbuffer.position(dbuffer.position() + 2);
    dbuffer.get(ordinates, 0, numpoints);
    for (int t = 0; t < numpoints; t++) {
      cs.setOrdinate(t, 2, ordinates[t]); // z
    }
  }
  return geometryFactory.createMultiPoint(cs);
}

代码示例来源:origin: geotools/geotools

private CoordinateSequence readCoordinateSequence(int size) throws IOException {
  CoordinateSequence seq =
      JTS.createCS(factory.getCoordinateSequenceFactory(), size, inputDimension);
  int targetDim = seq.getDimension();
  if (targetDim > inputDimension) targetDim = inputDimension;
  for (int i = 0; i < size; i++) {
    readCoordinate();
    for (int j = 0; j < targetDim; j++) {
      seq.setOrdinate(i, j, ordValues[j]);
    }
  }
  return seq;
}

代码示例来源:origin: geotools/geotools

/**
 * Builds an array of JTS <code>Coordinate</code> instances that's geometrically equals to the
 * <code>SeShape</code> single coordinates array passed as argument.
 *
 * @param coordList array of coordinates of a single shape part to build a <code>Coordinate
 *     </code> from
 * @return a geometrically equal to <code>coordList</code> array of <code>Coordinate</code>
 *     instances
 */
protected final CoordinateSequence toCoords(
    double[] coordList, final CoordinateSequenceFactory csFact) {
  final int dimension = 2;
  CoordinateSequence cs;
  if (csFact instanceof LiteCoordinateSequenceFactory) {
    cs = ((LiteCoordinateSequenceFactory) csFact).create(coordList, dimension);
  } else {
    final int nCoords = coordList.length / dimension;
    cs = JTS.createCS(csFact, nCoords, dimension);
    for (int coordN = 0; coordN < nCoords; coordN++) {
      cs.setOrdinate(coordN, 0, coordList[dimension * coordN]);
      cs.setOrdinate(coordN, 1, coordList[dimension * coordN + 1]);
    }
  }
  return cs;
}

代码示例来源:origin: geotools/geotools

/**
 * @param buffer
 * @param numPoints
 */
private CoordinateSequence readCoordinates(
    final ByteBuffer buffer, final int numPoints, final int dimensions) {
  CoordinateSequence cs =
      JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), numPoints, dimensions);
  DoubleBuffer dbuffer = buffer.asDoubleBuffer();
  double[] ordinates = new double[numPoints * 2];
  dbuffer.get(ordinates);
  for (int t = 0; t < numPoints; t++) {
    cs.setOrdinate(t, 0, ordinates[t * 2]);
    cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
  }
  if (dimensions > 2) {
    // z
    dbuffer.position(dbuffer.position() + 2);
    dbuffer.get(ordinates, 0, numPoints);
    for (int t = 0; t < numPoints; t++) {
      cs.setOrdinate(t, 2, ordinates[t]);
    }
  }
  return cs;
}

代码示例来源:origin: geotools/geotools

seq = JTS.createCS(csFactory, coordinates.size(), dimension);

代码示例来源:origin: geotools/geotools

seq = JTS.createCS(csFactory, coordinates.size(), dimension);

代码示例来源:origin: geotools/geotools

/**
 * Turns the array of ordinates into a coordinate sequence
 *
 * @param gf
 * @return
 */
public CoordinateSequence toCoordinateSequence(GeometryFactory gf) {
  double[] data = getData();
  CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), data.length / 2, 2);
  for (int i = 0; i < cs.size(); i++) {
    cs.setOrdinate(i, 0, data[i * 2]);
    cs.setOrdinate(i, 1, data[i * 2 + 1]);
  }
  return cs;
}

代码示例来源:origin: geotools/geotools

List<Polygon> getFaces(GeometryFactory gf, double extrude) {
    // sort the segments from bottom to top
    Collections.sort(segments);
    // extrude each segment
    List<Polygon> result = new ArrayList<Polygon>();
    for (Segment segment : segments) {
      CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), 5, 2);
      cs.setOrdinate(0, 0, segment.x0);
      cs.setOrdinate(0, 1, segment.y0);
      cs.setOrdinate(3, 0, segment.x0);
      cs.setOrdinate(3, 1, segment.y0 + extrude);
      cs.setOrdinate(2, 0, segment.x1);
      cs.setOrdinate(2, 1, segment.y1 + extrude);
      cs.setOrdinate(1, 0, segment.x1);
      cs.setOrdinate(1, 1, segment.y1);
      cs.setOrdinate(4, 0, segment.x0);
      cs.setOrdinate(4, 1, segment.y0);
      result.add(gf.createPolygon(gf.createLinearRing(cs), null));
    }
    return result;
  }
}

代码示例来源:origin: geotools/geotools

CoordinateSequenceFactory csf = factory.getCoordinateSequenceFactory();
if (Point.class.equals(type)) {
  CoordinateSequence cs = JTS.createCS(csf, 1, 2);
  cs.setOrdinate(0, 0, (minX + maxX) / 2);
  cs.setOrdinate(0, 1, (minY + maxY) / 2);
  return factory.createMultiPoint(new Point[] {p});
} else if (LineString.class.equals(type) || LinearRing.class.equals(type)) {
  CoordinateSequence cs = JTS.createCS(csf, 2, 2);
  cs.setOrdinate(0, 0, minX);
  cs.setOrdinate(0, 1, minY);
  return factory.createMultiLineString(new LineString[] {ls});
} else if (Polygon.class.equals(type)) {
  CoordinateSequence cs = JTS.createCS(csf, 5, 2);
  cs.setOrdinate(0, 0, minX);
  cs.setOrdinate(0, 1, minY);

代码示例来源:origin: geotools/geotools

/**
 * Does what it says, reverses the order of the Coordinates in the ring.
 *
 * <p>This is different then lr.reverses() in that a copy is produced using a new coordinate
 * sequence.
 *
 * @param lr The ring to reverse.
 * @return A new ring with the reversed Coordinates.
 */
public static final LinearRing reverseRing(LinearRing lr) {
  GeometryFactory gf = lr.getFactory();
  CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();
  CoordinateSequence csOrig = lr.getCoordinateSequence();
  int numPoints = csOrig.size();
  int dimensions = csOrig.getDimension();
  CoordinateSequence csNew = JTS.createCS(csf, numPoints, dimensions, csOrig.getMeasures());
  for (int i = 0; i < numPoints; i++) {
    for (int j = 0; j < dimensions; j++) {
      csNew.setOrdinate(numPoints - 1 - i, j, csOrig.getOrdinate(i, j));
    }
  }
  return gf.createLinearRing(csNew);
}

代码示例来源:origin: geotools/geotools

/**
 * Builds a linear ring representing the clipping area
 *
 * @param gf
 * @param csf
 * @return
 */
LinearRing buildBoundsString(final GeometryFactory gf, final CoordinateSequenceFactory csf) {
  CoordinateSequence cs = JTS.createCS(csf, 5, 2);
  cs.setOrdinate(0, 0, xmin);
  cs.setOrdinate(0, 1, ymin);
  cs.setOrdinate(1, 0, xmin);
  cs.setOrdinate(1, 1, ymax);
  cs.setOrdinate(2, 0, xmax);
  cs.setOrdinate(2, 1, ymax);
  cs.setOrdinate(3, 0, xmax);
  cs.setOrdinate(3, 1, ymin);
  cs.setOrdinate(4, 0, xmin);
  cs.setOrdinate(4, 1, ymin);
  return gf.createLinearRing(cs);
}

代码示例来源:origin: geotools/geotools

public Object getSimplifiedShape() {
  CoordinateSequenceFactory csf = geometryFactory.getCoordinateSequenceFactory();
  if (type.isPointType()) {
    CoordinateSequence cs = JTS.createCS(csf, 1, 2);
    cs.setOrdinate(0, 0, (minX + maxX) / 2);
    cs.setOrdinate(0, 1, (minY + maxY) / 2);
        new Point[] {geometryFactory.createPoint(cs)});
  } else if (type.isLineType()) {
    CoordinateSequence cs = JTS.createCS(csf, 2, 2);
    cs.setOrdinate(0, 0, minX);
    cs.setOrdinate(0, 1, minY);
        new LineString[] {geometryFactory.createLineString(cs)});
  } else if (type.isPolygonType()) {
    CoordinateSequence cs = JTS.createCS(csf, 5, 2);
    cs.setOrdinate(0, 0, minX);
    cs.setOrdinate(0, 1, minY);

代码示例来源:origin: geotools/geotools

/**
 * Construct CoordinateSequence with no LRS measures.
 *
 * <p>To produce two dimension Coordinates pass in <code>null</code> for z
 *
 * @param f DOCUMENT ME!
 * @param x DOCUMENT ME!
 * @param y DOCUMENT ME!
 * @param z DOCUMENT ME!
 * @return DOCUMENT ME!
 */
public static CoordinateSequence coordiantes(
    CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z) {
  final int LENGTH = x.size();
  // Coordinate[] array = new Coordinate[LENGTH];
  CoordinateSequence cs = JTS.createCS(f, LENGTH, z == null ? 2 : 3);
  if (z != null) {
    for (int i = 0; i < LENGTH; i++) {
      cs.setOrdinate(i, 0, x.getDouble(i));
      cs.setOrdinate(i, 1, y.getDouble(i));
      cs.setOrdinate(i, 2, z.getDouble(i));
    }
  } else {
    for (int i = 0; i < LENGTH; i++) {
      cs.setOrdinate(i, 0, x.getDouble(i));
      cs.setOrdinate(i, 1, y.getDouble(i));
    }
  }
  return cs;
}

代码示例来源:origin: geotools/geotools

CoordinateSequence cs = JTS.createCS(f, LENGTH, z == null ? 2 : 3);

相关文章