private JSONBuilder writeCoordinate(double x, double y, double z) { return writeCoordinate(x, y, z, Double.NaN); }
case POINT: Point point = (Point) geometry; writeCoordinate(point); break; case LINESTRING: this.array(); for (int i = 0, n = geometry.getNumGeometries(); i < n; i++) { writeCoordinate((Point) geometry.getGeometryN(i));
private JSONBuilder writeCoordinate(double x, double y) { return writeCoordinate(x, y, Double.NaN); }
/** * Helper method that encodes a {@see Point} coordinate to the JSON output. This method will * respect the configured axis order. If activated, coordinates measures (M) will be encoded, * otherwise measures will be ignored. * * @param point the point whose coordinate will be encoded * @return the JSON builder instance, this allow chained calls */ private JSONBuilder writeCoordinate(Point point) throws JSONException { CoordinateSequence coordinates = point.getCoordinateSequence(); // let's see if we need to encode measures, NaN values will not be encoded double m = encodeMeasures ? coordinates.getM(0) : Double.NaN; return writeCoordinate(coordinates.getX(0), coordinates.getY(0), coordinates.getZ(0), m); }
/** * Helper method that encodes a sequence of coordinates to the JSON output as an array. This * method will respect the configured axis order. If activated, coordinates measures (M) will be * encoded, otherwise measures will be ignored. * * @param coordinates the coordinates sequence that will be encoded * @return the JSON builder instance, this allow chained calls */ private JSONBuilder writeCoordinates(CoordinateSequence coordinates) throws JSONException { // start encoding the JSON array of coordinates this.array(); // each coordinate will be encoded has an array of ordinates for (int i = 0; i < coordinates.size(); i++) { // let's see if we need to encode measures, NaN values will not be encoded double m = encodeMeasures ? coordinates.getM(i) : Double.NaN; // encode the coordinate ordinates to the JSON output writeCoordinate(coordinates.getX(i), coordinates.getY(i), coordinates.getZ(i), m); } // we are done with the array return this.endArray(); }