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

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

本文整理了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

  1. /**
  2. * Creates a {@link CoordinateSequence} using the provided factory confirming the provided size
  3. * and dimension are respected.
  4. *
  5. * <p>If the requested dimension is larger than the CoordinateSequence implementation can
  6. * provide, then a sequence of maximum possible dimension should be created. An error should not
  7. * be thrown.
  8. *
  9. * <p>This method is functionally identical to calling csFactory.create(size,dim) - it contains
  10. * additional logic to work around a limitation on the commonly used
  11. * CoordinateArraySequenceFactory.
  12. *
  13. * @param size the number of coordinates in the sequence
  14. * @param dimension the dimension of the coordinates in the sequence
  15. */
  16. public static CoordinateSequence createCS(
  17. CoordinateSequenceFactory csFactory, int size, int dimension) {
  18. // the coordinates don't have measures
  19. return createCS(csFactory, size, dimension, 0);
  20. }

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

  1. @Override
  2. public void newSubPart(final int numPoints) {
  3. this.subPartNo++;
  4. this.currPartNumPoints = numPoints;
  5. this.currPointNo = 0;
  6. final int dimension = 2;
  7. this.currCoordSeq =
  8. JTS.createCS(gf.getCoordinateSequenceFactory(), numPoints, dimension);
  9. }

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

  1. private CoordinateSequence readCoordinateSequence(int size) throws IOException {
  2. CoordinateSequence seq = JTS.createCS(csFactory, size, inputDimension, inputMeasures);
  3. int targetDim = seq.getDimension();
  4. if (targetDim > inputDimension) targetDim = inputDimension;
  5. for (int i = 0; i < size; i++) {
  6. readCoordinate();
  7. for (int j = 0; j < targetDim; j++) {
  8. seq.setOrdinate(i, j, ordValues[j]);
  9. }
  10. }
  11. return seq;
  12. }

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

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

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

  1. public Object read(ByteBuffer buffer, ShapeType type, boolean flatGeometry) {
  2. if (type == ShapeType.NULL) {
  3. return createNull();
  4. }
  5. int dimension = shapeType == ShapeType.POINTZ && !flatGeometry ? 3 : 2;
  6. CoordinateSequence cs =
  7. JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), 1, dimension);
  8. cs.setOrdinate(0, 0, buffer.getDouble());
  9. cs.setOrdinate(0, 1, buffer.getDouble());
  10. if (shapeType == ShapeType.POINTM) {
  11. buffer.getDouble();
  12. }
  13. if (dimension > 2) {
  14. cs.setOrdinate(0, 2, buffer.getDouble());
  15. }
  16. return geometryFactory.createPoint(cs);
  17. }

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

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

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

  1. public Object read(ByteBuffer buffer, ShapeType type, boolean flatGeometry) {
  2. if (type == ShapeType.NULL) {
  3. return createNull();
  4. }
  5. // read bounding box (not needed)
  6. buffer.position(buffer.position() + 4 * 8);
  7. int numpoints = buffer.getInt();
  8. int dimensions = shapeType == shapeType.MULTIPOINTZ && !flatGeometry ? 3 : 2;
  9. CoordinateSequence cs =
  10. JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), numpoints, dimensions);
  11. DoubleBuffer dbuffer = buffer.asDoubleBuffer();
  12. double[] ordinates = new double[numpoints * 2];
  13. dbuffer.get(ordinates);
  14. for (int t = 0; t < numpoints; t++) {
  15. cs.setOrdinate(t, 0, ordinates[t * 2]);
  16. cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
  17. }
  18. if (dimensions > 2) {
  19. dbuffer.position(dbuffer.position() + 2);
  20. dbuffer.get(ordinates, 0, numpoints);
  21. for (int t = 0; t < numpoints; t++) {
  22. cs.setOrdinate(t, 2, ordinates[t]); // z
  23. }
  24. }
  25. return geometryFactory.createMultiPoint(cs);
  26. }

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

  1. private CoordinateSequence readCoordinateSequence(int size) throws IOException {
  2. CoordinateSequence seq =
  3. JTS.createCS(factory.getCoordinateSequenceFactory(), size, inputDimension);
  4. int targetDim = seq.getDimension();
  5. if (targetDim > inputDimension) targetDim = inputDimension;
  6. for (int i = 0; i < size; i++) {
  7. readCoordinate();
  8. for (int j = 0; j < targetDim; j++) {
  9. seq.setOrdinate(i, j, ordValues[j]);
  10. }
  11. }
  12. return seq;
  13. }

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

  1. /**
  2. * Builds an array of JTS <code>Coordinate</code> instances that's geometrically equals to the
  3. * <code>SeShape</code> single coordinates array passed as argument.
  4. *
  5. * @param coordList array of coordinates of a single shape part to build a <code>Coordinate
  6. * </code> from
  7. * @return a geometrically equal to <code>coordList</code> array of <code>Coordinate</code>
  8. * instances
  9. */
  10. protected final CoordinateSequence toCoords(
  11. double[] coordList, final CoordinateSequenceFactory csFact) {
  12. final int dimension = 2;
  13. CoordinateSequence cs;
  14. if (csFact instanceof LiteCoordinateSequenceFactory) {
  15. cs = ((LiteCoordinateSequenceFactory) csFact).create(coordList, dimension);
  16. } else {
  17. final int nCoords = coordList.length / dimension;
  18. cs = JTS.createCS(csFact, nCoords, dimension);
  19. for (int coordN = 0; coordN < nCoords; coordN++) {
  20. cs.setOrdinate(coordN, 0, coordList[dimension * coordN]);
  21. cs.setOrdinate(coordN, 1, coordList[dimension * coordN + 1]);
  22. }
  23. }
  24. return cs;
  25. }

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

  1. /**
  2. * @param buffer
  3. * @param numPoints
  4. */
  5. private CoordinateSequence readCoordinates(
  6. final ByteBuffer buffer, final int numPoints, final int dimensions) {
  7. CoordinateSequence cs =
  8. JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), numPoints, dimensions);
  9. DoubleBuffer dbuffer = buffer.asDoubleBuffer();
  10. double[] ordinates = new double[numPoints * 2];
  11. dbuffer.get(ordinates);
  12. for (int t = 0; t < numPoints; t++) {
  13. cs.setOrdinate(t, 0, ordinates[t * 2]);
  14. cs.setOrdinate(t, 1, ordinates[t * 2 + 1]);
  15. }
  16. if (dimensions > 2) {
  17. // z
  18. dbuffer.position(dbuffer.position() + 2);
  19. dbuffer.get(ordinates, 0, numPoints);
  20. for (int t = 0; t < numPoints; t++) {
  21. cs.setOrdinate(t, 2, ordinates[t]);
  22. }
  23. }
  24. return cs;
  25. }

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

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

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

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

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

  1. /**
  2. * Turns the array of ordinates into a coordinate sequence
  3. *
  4. * @param gf
  5. * @return
  6. */
  7. public CoordinateSequence toCoordinateSequence(GeometryFactory gf) {
  8. double[] data = getData();
  9. CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), data.length / 2, 2);
  10. for (int i = 0; i < cs.size(); i++) {
  11. cs.setOrdinate(i, 0, data[i * 2]);
  12. cs.setOrdinate(i, 1, data[i * 2 + 1]);
  13. }
  14. return cs;
  15. }

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

  1. List<Polygon> getFaces(GeometryFactory gf, double extrude) {
  2. // sort the segments from bottom to top
  3. Collections.sort(segments);
  4. // extrude each segment
  5. List<Polygon> result = new ArrayList<Polygon>();
  6. for (Segment segment : segments) {
  7. CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), 5, 2);
  8. cs.setOrdinate(0, 0, segment.x0);
  9. cs.setOrdinate(0, 1, segment.y0);
  10. cs.setOrdinate(3, 0, segment.x0);
  11. cs.setOrdinate(3, 1, segment.y0 + extrude);
  12. cs.setOrdinate(2, 0, segment.x1);
  13. cs.setOrdinate(2, 1, segment.y1 + extrude);
  14. cs.setOrdinate(1, 0, segment.x1);
  15. cs.setOrdinate(1, 1, segment.y1);
  16. cs.setOrdinate(4, 0, segment.x0);
  17. cs.setOrdinate(4, 1, segment.y0);
  18. result.add(gf.createPolygon(gf.createLinearRing(cs), null));
  19. }
  20. return result;
  21. }
  22. }

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

  1. CoordinateSequenceFactory csf = factory.getCoordinateSequenceFactory();
  2. if (Point.class.equals(type)) {
  3. CoordinateSequence cs = JTS.createCS(csf, 1, 2);
  4. cs.setOrdinate(0, 0, (minX + maxX) / 2);
  5. cs.setOrdinate(0, 1, (minY + maxY) / 2);
  6. return factory.createMultiPoint(new Point[] {p});
  7. } else if (LineString.class.equals(type) || LinearRing.class.equals(type)) {
  8. CoordinateSequence cs = JTS.createCS(csf, 2, 2);
  9. cs.setOrdinate(0, 0, minX);
  10. cs.setOrdinate(0, 1, minY);
  11. return factory.createMultiLineString(new LineString[] {ls});
  12. } else if (Polygon.class.equals(type)) {
  13. CoordinateSequence cs = JTS.createCS(csf, 5, 2);
  14. cs.setOrdinate(0, 0, minX);
  15. cs.setOrdinate(0, 1, minY);

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

  1. /**
  2. * Does what it says, reverses the order of the Coordinates in the ring.
  3. *
  4. * <p>This is different then lr.reverses() in that a copy is produced using a new coordinate
  5. * sequence.
  6. *
  7. * @param lr The ring to reverse.
  8. * @return A new ring with the reversed Coordinates.
  9. */
  10. public static final LinearRing reverseRing(LinearRing lr) {
  11. GeometryFactory gf = lr.getFactory();
  12. CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();
  13. CoordinateSequence csOrig = lr.getCoordinateSequence();
  14. int numPoints = csOrig.size();
  15. int dimensions = csOrig.getDimension();
  16. CoordinateSequence csNew = JTS.createCS(csf, numPoints, dimensions, csOrig.getMeasures());
  17. for (int i = 0; i < numPoints; i++) {
  18. for (int j = 0; j < dimensions; j++) {
  19. csNew.setOrdinate(numPoints - 1 - i, j, csOrig.getOrdinate(i, j));
  20. }
  21. }
  22. return gf.createLinearRing(csNew);
  23. }

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

  1. /**
  2. * Builds a linear ring representing the clipping area
  3. *
  4. * @param gf
  5. * @param csf
  6. * @return
  7. */
  8. LinearRing buildBoundsString(final GeometryFactory gf, final CoordinateSequenceFactory csf) {
  9. CoordinateSequence cs = JTS.createCS(csf, 5, 2);
  10. cs.setOrdinate(0, 0, xmin);
  11. cs.setOrdinate(0, 1, ymin);
  12. cs.setOrdinate(1, 0, xmin);
  13. cs.setOrdinate(1, 1, ymax);
  14. cs.setOrdinate(2, 0, xmax);
  15. cs.setOrdinate(2, 1, ymax);
  16. cs.setOrdinate(3, 0, xmax);
  17. cs.setOrdinate(3, 1, ymin);
  18. cs.setOrdinate(4, 0, xmin);
  19. cs.setOrdinate(4, 1, ymin);
  20. return gf.createLinearRing(cs);
  21. }

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

  1. public Object getSimplifiedShape() {
  2. CoordinateSequenceFactory csf = geometryFactory.getCoordinateSequenceFactory();
  3. if (type.isPointType()) {
  4. CoordinateSequence cs = JTS.createCS(csf, 1, 2);
  5. cs.setOrdinate(0, 0, (minX + maxX) / 2);
  6. cs.setOrdinate(0, 1, (minY + maxY) / 2);
  7. new Point[] {geometryFactory.createPoint(cs)});
  8. } else if (type.isLineType()) {
  9. CoordinateSequence cs = JTS.createCS(csf, 2, 2);
  10. cs.setOrdinate(0, 0, minX);
  11. cs.setOrdinate(0, 1, minY);
  12. new LineString[] {geometryFactory.createLineString(cs)});
  13. } else if (type.isPolygonType()) {
  14. CoordinateSequence cs = JTS.createCS(csf, 5, 2);
  15. cs.setOrdinate(0, 0, minX);
  16. cs.setOrdinate(0, 1, minY);

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

  1. /**
  2. * Construct CoordinateSequence with no LRS measures.
  3. *
  4. * <p>To produce two dimension Coordinates pass in <code>null</code> for z
  5. *
  6. * @param f DOCUMENT ME!
  7. * @param x DOCUMENT ME!
  8. * @param y DOCUMENT ME!
  9. * @param z DOCUMENT ME!
  10. * @return DOCUMENT ME!
  11. */
  12. public static CoordinateSequence coordiantes(
  13. CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z) {
  14. final int LENGTH = x.size();
  15. // Coordinate[] array = new Coordinate[LENGTH];
  16. CoordinateSequence cs = JTS.createCS(f, LENGTH, z == null ? 2 : 3);
  17. if (z != null) {
  18. for (int i = 0; i < LENGTH; i++) {
  19. cs.setOrdinate(i, 0, x.getDouble(i));
  20. cs.setOrdinate(i, 1, y.getDouble(i));
  21. cs.setOrdinate(i, 2, z.getDouble(i));
  22. }
  23. } else {
  24. for (int i = 0; i < LENGTH; i++) {
  25. cs.setOrdinate(i, 0, x.getDouble(i));
  26. cs.setOrdinate(i, 1, y.getDouble(i));
  27. }
  28. }
  29. return cs;
  30. }

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

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

相关文章