Refine search
final CoordinateSequence coordSeq = geomFactory.getCoordinateSequenceFactory().create(cmdLength, 2); int coordIndex = 0; Coordinate nextCoord; ); nextCoord = coordSeq.getCoordinate(coordIndex++); nextCoord.setOrdinate(0, cursor.x); nextCoord.setOrdinate(1, cursor.y); return coordSeq.size() == 1 ? geomFactory.createPoint(coordSeq) : geomFactory.createMultiPoint(coordSeq);
public Object getSimplifiedShape() { CoordinateSequenceFactory csf = geometryFactory.getCoordinateSequenceFactory(); if(type.isPointType()) { CoordinateSequence cs = csf.create(1, 2); cs.setOrdinate(0, 0, (minX + maxX) / 2); cs.setOrdinate(0, 1, (minY + maxY) / 2); return geometryFactory.createMultiPoint(new Point[] {geometryFactory.createPoint(cs)}); } else if(type.isLineType()) { CoordinateSequence cs = csf.create(2, 2); cs.setOrdinate(0, 0, minX); cs.setOrdinate(0, 1, minY); cs.setOrdinate(1, 0, maxX); return geometryFactory.createMultiLineString(new LineString[] {geometryFactory.createLineString(cs)}); } else if(type.isPolygonType()) { CoordinateSequence cs = csf.create(5, 2); cs.setOrdinate(0, 0, minX); cs.setOrdinate(0, 1, minY);
CoordinateSequence sequenceWithoutDuplicates = makeSequenceValid(sequence, false, false); GeometryFactory factory = lineString.getFactory(); if (sequenceWithoutDuplicates.size() == 0) { return factory.createLineString(factory.getCoordinateSequenceFactory().create(0, sequence.getDimension())); } else if (sequenceWithoutDuplicates.size() == 1) { return factory.createLineString(factory.getCoordinateSequenceFactory().create(0, sequence.getDimension())); } else { return factory.createPoint(sequenceWithoutDuplicates);
nextCoordSeq = geomFactory.getCoordinateSequenceFactory().create(2 + cmdLength, 2); nextCoord = nextCoordSeq.getCoordinate(0); nextCoord.setOrdinate(0, cursor.x); nextCoord.setOrdinate(1, cursor.y); ); nextCoord = nextCoordSeq.getCoordinate(lineToIndex + 1); nextCoord.setOrdinate(0, cursor.x); nextCoord.setOrdinate(1, cursor.y); nextCoord = nextCoordSeq.getCoordinate(nextCoordSeq.size() - 1); nextCoord.setOrdinate(0, nextCoordSeq.getOrdinate(0, 0)); nextCoord.setOrdinate(1, nextCoordSeq.getOrdinate(0, 1)); rings.add(geomFactory.createLinearRing(nextCoordSeq)); return geomFactory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
/** * Creates a {@link MultiPoint} using the * points in the given {@link CoordinateSequence}. * A <code>null</code> or empty CoordinateSequence creates an empty MultiPoint. * * @param coordinates a CoordinateSequence (possibly empty), or <code>null</code> * @return a MultiPoint geometry */ public MultiPoint createMultiPoint(CoordinateSequence coordinates) { if (coordinates == null) { return createMultiPoint(new Point[0]); } Point[] points = new Point[coordinates.size()]; for (int i = 0; i < coordinates.size(); i++) { CoordinateSequence ptSeq = getCoordinateSequenceFactory() .create(1, coordinates.getDimension()); CoordinateSequences.copy(coordinates, i, ptSeq, 0, 1); points[i] = createPoint(ptSeq); } return createMultiPoint(points); }
/** @deprecated Use GeometryFactory instead */ public LineString(Coordinate points[], PrecisionModel precisionModel, int SRID) { super(new GeometryFactory(precisionModel, SRID)); init(getFactory().getCoordinateSequenceFactory().create(points)); }
private Point makePointValid(Point point) { CoordinateSequence sequence = point.getCoordinateSequence(); GeometryFactory factory = point.getFactory(); CoordinateSequenceFactory csFactory = factory.getCoordinateSequenceFactory(); if (sequence.size() == 0) { return point; } else if (Double.isNaN(sequence.getOrdinate(0, 0)) || Double.isNaN(sequence.getOrdinate(0, 1))) { return factory.createPoint(csFactory.create(0, sequence.getDimension())); } else if (sequence.size() == 1) { return point; } else { throw new RuntimeException("JTS cannot create a point from a CoordinateSequence containing several points"); } }
/** * 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. * </p> * @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 = csf.create(numPoints, dimensions); 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); }
nextCoordSeq = geomFactory.getCoordinateSequenceFactory().create(1 + cmdLength, 2); nextCoord = nextCoordSeq.getCoordinate(0); nextCoord.setOrdinate(0, cursor.x); nextCoord.setOrdinate(1, cursor.y); ); nextCoord = nextCoordSeq.getCoordinate(lineToIndex + 1); nextCoord.setOrdinate(0, cursor.x); nextCoord.setOrdinate(1, cursor.y); geoms.add(geomFactory.createLineString(nextCoordSeq)); return geoms.size() == 1 ? geoms.get(0) : geomFactory.createMultiLineString(geoms.toArray(new LineString[geoms.size()]));
public LinearRing createLinearRing(CoordinateSequence cs) { if (cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1))) return super.createLinearRing(cs); // add a new coordinate to close the ring CoordinateSequenceFactory csFact = getCoordinateSequenceFactory(); CoordinateSequence csNew = csFact.create(cs.size() + 1, cs.getDimension()); CoordinateSequences.copy(cs, 0, csNew, 0, cs.size()); CoordinateSequences.copyCoord(csNew, 0, csNew, csNew.size() - 1); return super.createLinearRing(csNew); }
public static Polygon constructRectyPolygon(Point2D.Double aLeftUpperCorner, Point2D.Double aBottomRightCorner) { Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(aLeftUpperCorner.x, aLeftUpperCorner.y); coordinates[1] = new Coordinate(aBottomRightCorner.x, aLeftUpperCorner.y); coordinates[2] = new Coordinate(aBottomRightCorner.x, aBottomRightCorner.y); coordinates[3] = new Coordinate(aLeftUpperCorner.x, aBottomRightCorner.y); coordinates[4] = new Coordinate(aLeftUpperCorner.x, aLeftUpperCorner.y); CoordinateSequence cSeq = csFactory.create(coordinates); return gFactory.createPolygon(new LinearRing(cSeq, gFactory), null); }
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 = geometryFactory.getCoordinateSequenceFactory().create(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); }
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 = gf.getCoordinateSequenceFactory().create(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; }
/** * Creates a Point using the given Coordinate; a null Coordinate will create * an empty Geometry. */ public Point createPoint(Coordinate coordinate) { return createPoint(coordinate != null ? getCoordinateSequenceFactory().create(new Coordinate[]{coordinate}) : null); }
DirectPosition dp = (DirectPosition) dps.get(0); CoordinateSequence seq = csf.create(dps.size(), dp.getDimension()); seq.setOrdinate(i, j, dp.getOrdinate(j)); return ring ? gf.createLinearRing(seq) : gf.createLineString(seq); return ring ? gf.createLinearRing(coordinates) : gf.createLineString(coordinates); seq = csf.create(0, 0); } else { seq = csf.create(dps.length, dps[0].getDimension()); seq.setOrdinate(i, j, dp.getOrdinate(j));
/** * Creates a {@link LinearRing} using the given {@link Coordinate}s. * A null or empty array will * create an empty LinearRing. The points must form a closed and simple * linestring. Consecutive points must not be equal. * @param coordinates an array without null elements, or an empty array, or null */ public LinearRing createLinearRing(Coordinate[] coordinates) { return createLinearRing(coordinates != null ? getCoordinateSequenceFactory().create(coordinates) : null); }
/** * Creates a LineString using the given Coordinates; a null or empty array will * create an empty LineString. Consecutive points must not be equal. * @param coordinates an array without null elements, or an empty array, or null */ public LineString createLineString(Coordinate[] coordinates) { return createLineString(coordinates != null ? getCoordinateSequenceFactory().create(coordinates) : null); } /**
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 = geometryFactory.getCoordinateSequenceFactory().create(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); }
int dimension = GMLUtil.getDimension(seq); CoordinateSequence lineSeq = csFactory.create(coordinates.size(), dimension); lineSeq.setOrdinate(i, j, seq.getOrdinate(0, j)); return gFactory.createLinearRing(lineSeq); CoordinateSequence lineSeq = (CoordinateSequence) cnode.getValue(); return gFactory.createLinearRing(lineSeq);
/** * @param buffer * @param numPoints * @throws java.io.IOException */ private CoordinateSequence readCoordinates(final ReadBufferManager buffer, final int numPoints, final int dimensions) throws IOException { CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(numPoints, dimensions); for (int t = 0; t < numPoints; t++) { cs.setOrdinate(t, 0, buffer.getDouble()); cs.setOrdinate(t, 1, buffer.getDouble()); } return cs; }