/** * @see org.locationtech.jts.geom.CoordinateSequence#setOrdinate(int, int, double) */ public void setOrdinate(int index, int ordinateIndex, double value) { switch (ordinateIndex) { case CoordinateSequence.X: coordinates[index].x = value; break; case CoordinateSequence.Y: coordinates[index].y = value; break; case CoordinateSequence.Z: coordinates[index].setZ(value); break; } } /**
public void setZ(double _z) { p.setZ(_z); }
/** * Sets the ordinate for the given index * to a given value. * * The base implementation supported values for the index are * {@link X}, {@link Y}, and {@link Z}. * * @param ordinateIndex the ordinate index * @param value the value to set * @throws IllegalArgumentException if the index is not valid */ public void setOrdinate(int ordinateIndex, double value) { switch (ordinateIndex) { case X: x = value; break; case Y: y = value; break; case Z: setZ(value); // delegate to subclass rather than offer direct field access break; default: throw new IllegalArgumentException("Invalid ordinate index: " + ordinateIndex); } }
public void filter(Coordinate coord) { coord.setZ((coord.x + coord.y) / 2); } }
public Object parse(Handler arg, GeometryFactory gf) throws SAXException { // one child, either a coord // or a coordinate sequence if(arg.children.size()<1) throw new SAXException("Cannot create a coordinate without atleast one axis"); if(arg.children.size()>3) throw new SAXException("Cannot create a coordinate with more than 3 axis"); Double[] axis = (Double[]) arg.children.toArray(new Double[arg.children.size()]); Coordinate c = new Coordinate(); c.x = axis[0].doubleValue(); if(axis.length>1) c.y = axis[1].doubleValue(); if(axis.length>2) c.setZ(axis[2].doubleValue()); return c; } });
/** * @see org.locationtech.jts.geom.CoordinateSequence#getX(int) */ public void getCoordinate(int index, Coordinate coord) { coord.x = coordinates[index].x; coord.y = coordinates[index].y; coord.setZ( coordinates[index].getZ()); coord.setM( coordinates[index].getM()); }
public void getCoordinate(int index, Coordinate coord) { coord.x = getOrdinate(index, X); coord.y = getOrdinate(index, Y); coord.setZ(getOrdinate(index, Z)); }
private Coordinate toCoordinateXYZ(double[] c) { Coordinate co = new Coordinate(); co.setX(c[0]); co.setY(c[1]); co.setZ(c[2]); return co; }
@Override public Coordinate readPoint(DataInput input) throws IOException { Coordinate coordinate = super.readPoint(input); if (hasZ) { coordinate.setZ(Varint.readSignedVarLong(input) / zPrecisionMultiplier); } if (hasM) { coordinate.setM(Varint.readSignedVarLong(input) / mPrecisionMultiplier); } return coordinate; }
/** * Computes a point which is the average of all coordinates * in a sequence. * If the sequence lies in a single plane, * the computed point also lies in the plane. * * @param seq a coordinate sequence * @return a Coordinate with averaged ordinates */ private Coordinate averagePoint(CoordinateSequence seq) { Coordinate a = new Coordinate(0,0,0); int n = seq.size(); for (int i = 0; i < n; i++) { a.x += seq.getOrdinate(i, CoordinateSequence.X); a.y += seq.getOrdinate(i, CoordinateSequence.Y); a.setZ(a.getZ() + seq.getOrdinate(i, CoordinateSequence.Z)); } a.x /= n; a.y /= n; a.setZ(a.getZ() / n); return a; }
/** * Sets <code>internal</code> to the precise representation of <code>external</code>. * * @param external the original coordinate * @param internal the coordinate whose values will be changed to the * precise representation of <code>external</code> * @deprecated use makePrecise instead */ public void toInternal (Coordinate external, Coordinate internal) { if (isFloating()) { internal.x = external.x; internal.y = external.y; } else { internal.x = makePrecise(external.x); internal.y = makePrecise(external.y); } internal.setZ(external.getZ()); }
/** * Confirm the z field is not supported by getZ and setZ. */ private void checkZUnsupported(Coordinate coord ) { try { coord.setZ(0.0); fail(coord.getClass().getSimpleName() + " does not support Z"); } catch(IllegalArgumentException expected) { } assertTrue( Double.isNaN(coord.z)); coord.z = 0.0; // field still public assertTrue( "z field not used", Double.isNaN(coord.getZ())); // but not used } /**
/** * @see org.locationtech.jts.geom.CoordinateSequence#getCoordinate(int) */ public void getCoordinate(int i, Coordinate coord) { coord.x = getOrdinate(i, 0); coord.y = getOrdinate(i, 1); if (hasZ()) { coord.setZ(getZ(i)); } if (hasM()) { coord.setM(getM(i)); } }
/** * Computes an average normal vector from a list of polygon coordinates. * Uses Newell's method, which is based * on the fact that the vector with components * equal to the areas of the projection of the polygon onto * the Cartesian axis planes is normal. * * @param seq the sequence of coordinates for the polygon * @return a normal vector */ private Vector3D averageNormal(CoordinateSequence seq) { int n = seq.size(); Coordinate sum = new Coordinate(0,0,0); Coordinate p1 = new Coordinate(0,0,0); Coordinate p2 = new Coordinate(0,0,0); for (int i = 0; i < n - 1; i++) { seq.getCoordinate(i, p1); seq.getCoordinate(i+1, p2); sum.x += (p1.y - p2.y)*(p1.getZ() + p2.getZ()); sum.y += (p1.getZ() - p2.getZ())*(p1.x + p2.x); sum.setZ(sum.getZ() + (p1.x - p2.x)*(p1.y + p2.y)); } sum.x /= n; sum.y /= n; sum.setZ(sum.getZ() / n); Vector3D norm = Vector3D.create(sum).normalize(); return norm; }
@Override public Coordinate[] readPointArray(DataInput input) throws IOException { int numCoordinates = Varint.readUnsignedVarInt(input); Coordinate[] coordinates = new Coordinate[numCoordinates]; long lastX = 0; long lastY = 0; long lastZ = 0; long lastM = 0; for (int i = 0; i < numCoordinates; i++) { lastX = Varint.readSignedVarLong(input) + lastX; lastY = Varint.readSignedVarLong(input) + lastY; coordinates[i] = new Coordinate( ((double) lastX) / precisionMultiplier, ((double) lastY) / precisionMultiplier); if (hasZ) { lastZ = Varint.readSignedVarLong(input) + lastZ; coordinates[i].setZ(((double) lastZ) / zPrecisionMultiplier); } if (hasM) { lastM = Varint.readSignedVarLong(input) + lastM; coordinates[i].setM(((double) lastM) / mPrecisionMultiplier); } } return coordinates; } }
/** * Returns the next precise <code>Coordinate</code> in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next element returned by the stream should be a number. *@return the next array of <code>Coordinate</code>s in the * stream. *@throws IOException if an I/O error occurs *@throws ParseException if an unexpected token was encountered * *@deprecated in favor of functions returning {@link CoordinateSequence}s */ private Coordinate getPreciseCoordinate(StreamTokenizer tokenizer) throws IOException, ParseException { Coordinate coord = new Coordinate(); coord.x = getNextNumber(tokenizer); coord.y = getNextNumber(tokenizer); if (isNumberNext(tokenizer)) { coord.setZ(getNextNumber(tokenizer)); } if (isNumberNext(tokenizer)) { getNextNumber(tokenizer); // ignore M value } precisionModel.makePrecise(coord); return coord; }
for(int t=0;t<numPoints;t++) coords[t].setZ(file.readDoubleLE()); actualReadWords += 4;
public void testCoordinateXYZM() { Coordinate xyzm = new CoordinateXYZM(); xyzm.setZ(1.0); assertEquals( 1.0, xyzm.getZ()); xyzm.setM(1.0); assertEquals( 1.0, xyzm.getM()); Coordinate coord = new Coordinate(xyzm); // copy assertEquals( xyzm, coord ); assertTrue( xyzm.equalInZ(coord,0.000001) ); assertTrue( Double.isNaN(coord.getM())); coord = new Coordinate(1.0,1.0,1.0); // 2.5d xyzm = new CoordinateXYZM( coord ); // copy assertEquals( xyzm, coord ); assertTrue( xyzm.equalInZ(coord,0.000001) ); }
coords[t].setZ(z);
coords[t].setZ(file.readDoubleLE()); //z value actualReadWords += 4;