/** * 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); }
@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); }
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; }
/** 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; }
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); }
cs = JTS.createCS(csFact, n, dim);
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); }
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; }
/** * 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; }
/** * @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; }
seq = JTS.createCS(csFactory, coordinates.size(), dimension);
seq = JTS.createCS(csFactory, coordinates.size(), dimension);
/** * 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; }
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; } }
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);
/** * 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); }
/** * 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); }
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);
/** * 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; }
CoordinateSequence cs = JTS.createCS(f, LENGTH, z == null ? 2 : 3);