/** * @see * org.geotools.geometry.coordinatesequence.CSBuilder#setOrdinate(org.locationtech.jts.geom.CoordinateSequence, * double, int, int) */ public void setOrdinate( CoordinateSequence sequence, double value, int ordinateIndex, int coordinateIndex) { Coordinate c = sequence.getCoordinate(coordinateIndex); switch (ordinateIndex) { case 0: c.x = value; break; case 1: c.y = value; break; case 2: c.z = value; break; } } }
public static void append( StringBuffer buf, CoordinateSequence cs, int coordinate, int LEN, NumberFormat nf) { Coordinate c = cs.getCoordinate(coordinate); buf.append(nf.format(c.x)); buf.append(" "); buf.append(nf.format(c.y)); if (LEN == 3) { buf.append(" "); buf.append(nf.format(c.z)); } }
public String encode(Object object, String value) throws Exception { StringBuffer sb = new StringBuffer(); CoordinateSequence cs = (CoordinateSequence) object; for (int i = 0; i < cs.size(); i++) { Coordinate c = cs.getCoordinate(i); sb.append(c.x).append(",").append(c.y); if (cs.getDimension() == 3 && !Double.isNaN(c.z)) { sb.append(",").append(c.z); } sb.append(" "); } sb.setLength(sb.length() - 1); return sb.toString(); } }
/** Returns the Point representing the current position along the LineString */ public Coordinate getCurrentPosition(Coordinate c) { c.setCoordinate(coords.getCoordinate(segment)); if (offsetDistance > 0) { final double angle = getCurrentAngle(); c.x += offsetDistance * Math.cos(angle); c.y += offsetDistance * Math.sin(angle); } return c; }
public void filter(CoordinateSequence seq, int i) { if (i == 0) { return; } p.add( new GeometryFactory() .createLineString( new Coordinate[] { seq.getCoordinate(i - 1), seq.getCoordinate(i) })); } });
public static int D(CoordinateSequence cs) { if (cs instanceof CoordinateAccess) { return ((CoordinateAccess) cs).getDimension(); } if (cs.size() > 0) { return Double.isNaN(cs.getCoordinate(0).z) ? 2 : 3; } return 3; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { CoordinateSequence coordinates = (CoordinateSequence) node.getChildValue(KML.coordinates.getLocalPart()); return geometryFactory.createPoint(coordinates.getCoordinate(0)); }
c = coords.getCoordinate(i); array[i] = (c != null) ? c.x : Double.NaN; c = coords.getCoordinate(i); array[i] = (c != null) ? c.y : Double.NaN; c = coords.getCoordinate(i); array[i] = (c != null) ? c.z : Double.NaN;
/** * hasPair purpose. * * <p>finds a pair of points, assumes the sequence is sorted smallest to largest. * * @param a1 * @param a2 */ private boolean hasPair(CoordinateSequence a1, CoordinateSequence a2) { int i = 0; CoordinateSequence c; c = a1; Set m = new HashSet(); while (i < c.size()) { m.add(c.getCoordinate(i)); i++; } i = 0; c = a2; while (i < c.size()) { if (!m.add(c.getCoordinate(i))) return true; i++; } return false; } }
public void writeJSONString(Writer out) throws IOException { int size = seq.size(); if (size > 1) { out.write("["); } for (int i = 0; i < seq.size(); i++) { Coordinate coord = seq.getCoordinate(i); out.write("["); out.write(String.valueOf(coord.x)); out.write(","); out.write(String.valueOf(coord.y)); if (!Double.isNaN(coord.z)) { out.write(","); out.write(String.valueOf(coord.z)); } out.write("]"); if (i < seq.size() - 1) { out.write(","); } } if (size > 1) { out.write("]"); } }
public Element encode(Object object, Document document, Element value) throws Exception { CoordinateSequence coordinates = (CoordinateSequence) object; StringBuffer buf = new StringBuffer(); for (int i = 0; i < coordinates.size(); i++) { Coordinate c = coordinates.getCoordinate(i); buf.append(c.x); boolean y = (coordinates.getDimension() > 1) && !new Double(c.y).isNaN(); if (y) { buf.append("," + c.y); } boolean z = y && (coordinates.getDimension() > 2) && !new Double(c.z).isNaN(); if (z) { buf.append("," + c.z); } if (i < (coordinates.size() - 1)) { buf.append(" "); } } value.appendChild(document.createTextNode(buf.toString())); return value; } }
public String toJSONString() { int size = seq.size(); StringBuilder sb = new StringBuilder(); if (size > 1) { sb.append("["); } for (int i = 0; i < seq.size(); i++) { Coordinate coord = seq.getCoordinate(i); sb.append("["); formatDecimal(coord.x, sb); sb.append(","); formatDecimal(coord.y, sb); if (!Double.isNaN(coord.z)) { sb.append(","); formatDecimal(coord.z, sb); } sb.append("],"); } sb.setLength(sb.length() - 1); if (size > 1) { sb.append("]"); } return sb.toString(); }
public void filter(Geometry geom) { // this filter will receive either points, which we don't consider, // or lines, that we need to wrap if (geom instanceof LineString) { LineString ls = (LineString) geom; CoordinateSequence cs = ls.getCoordinateSequence(); int direction = getDisconinuityDirection(cs); if (direction == NOWRAP) return; boolean ring = geom instanceof LinearRing || cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1)); applyOffset(cs, direction == EAST_TO_WEST ? 0 : wrapLimit * 2, ring); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { CoordinateSequence coordinates = (CoordinateSequence) node.getChildValue(KML.coordinates.getLocalPart()); // If the last point is not the same as the first point jts will throw an error // where as other KML readers like google earth just auto close the polygon so // here we manually fix it even though it's invalid so KMls that work elsewhere work here Coordinate firstCoord = coordinates.getCoordinate(0); Coordinate lastCoord = coordinates.getCoordinate(coordinates.size() - 1); if (!firstCoord.equals3D(lastCoord)) { List<Coordinate> updateCoords = new ArrayList<>(Arrays.asList(coordinates.toCoordinateArray())); updateCoords.add((Coordinate) firstCoord.clone()); coordinates = csFactory.create(updateCoords.toArray(new Coordinate[0])); } return geometryFactory.createLinearRing(coordinates); }
/** * Adds a double array to list. * * <p>The double array will contain all the ordinates in the Coordinate sequence. * * @param list * @param sequence */ private static void addCoordinates(List list, CoordinateSequence sequence) { double[] ords; if (sequence instanceof CoordinateAccess) { CoordinateAccess access = (CoordinateAccess) sequence; for (int i = 0; i < access.size(); i++) { list.add(ordinateArray(access, i)); } } else { for (int i = 0; i < sequence.size(); i++) { list.add(ordinateArray(sequence.getCoordinate(i))); } } }
if (oldCoord == null) { currentCoord++; oldCoord = coords.getCoordinate(currentCoord); } else { double distx = 0; oldCoord = coords.getCoordinate(currentCoord); } else { oldCoord = null;
assert cseq.getCoordinate(0).equals(cseq.getCoordinate(size-1)); assert shiftXPage == 0;//starts and ends at 0
.create( new Coordinate[] { c.getCoordinate(0), c.getCoordinate(0) });
/** * Returns the linestring that starts and ends at the specified curvilinear coordinates. * * @param startOrdinate * @param endOrdinate * @return */ public LineString getSubLineString(double startOrdinate, double endOrdinate) { LineStringCursor clone = new LineStringCursor(this); clone.moveTo(startOrdinate); int startSegment = clone.segment; Coordinate start = clone.getCurrentPosition(); clone.moveTo(endOrdinate); int endSegment = clone.segment; Coordinate end = clone.getCurrentPosition(); Coordinate[] subCoords = new Coordinate[endSegment - startSegment + 2]; subCoords[0] = start; for (int i = startSegment; i < endSegment; i++) { subCoords[i - startSegment + 1] = coords.getCoordinate(i + 1); } subCoords[subCoords.length - 1] = end; return lineString.getFactory().createLineString(subCoords); } }
assertEquals(sourceCS.size(), targetCS.size()); for (int i = sourceCS.size(); --i >= 0; ) { assertFalse(sourceCS.getCoordinate(i).equals(targetCS.getCoordinate(i))); assertEquals(sourceCS.size(), testCS.size()); for (int i = targetCS.size(); --i >= 0; ) { assertEquals(targetCS.getCoordinate(i), testCS.getCoordinate(i));