Package org.json

Examples of org.json.JSONArray


    // Write the response
    JsonObjectWriter writer = new JsonObjectWriter(response.getWriter(), 3);
    writer.write(jsonRes);
    writer.flush();

    JSONArray jsonArray = (JSONArray) jsonReq.get("params");
    long millis = System.currentTimeMillis() - startTime;
    log.debug("Command execution time: " + millis + " ms - class=" + jsonArray.toString());
  }
View Full Code Here


        type.equals(org.geomajas.geometry.Geometry.LINEAR_RING) ||
        type.equals(org.geomajas.geometry.Geometry.MULTI_LINE_STRING) ||
        type.equals(org.geomajas.geometry.Geometry.MULTI_POLYGON))) {
      throw new UnmarshallException(type + " is not a supported geometry");
    }
    JSONArray coordinates = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (coordinates == null) {
      throw new UnmarshallException("coordinates missing");
    }
    return ObjectMatch.OKAY;
  }
View Full Code Here

  private Polygon createPolygon(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    JSONObject jsoShell = jso.getJSONObject("shell");
    LinearRing shell = createLinearRing(factory, jsoShell);

    JSONArray holeArray = jso.getJSONArray("holes");
    LinearRing[] holes = new LinearRing[holeArray.length()];
    for (int i = 0; i < holeArray.length(); i++) {
      JSONObject jsoHole = holeArray.getJSONObject(i);
      holes[i] = createLinearRing(factory, jsoHole);
    }
    return factory.createPolygon(shell, holes);
  }
View Full Code Here

    }
    return factory.createPolygon(shell, holes);
  }

  private LinearRing createLinearRing(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    JSONArray coords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    Coordinate[] coordinates = new Coordinate[coords.length()];
    for (int i = 0; i < coords.length(); i++) {
      JSONObject nextCoord = coords.getJSONObject(i);
      if (nextCoord == null) {
        throw new UnmarshallException("inner coordinate missing");
      }
      coordinates[i] = new Coordinate(nextCoord.getDouble("x"), nextCoord.getDouble("y"));
    }
View Full Code Here

    return factory.createLinearRing(coordinates);
  }

  private LineString createLineString(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    LineString geometry;
    JSONArray jsonCoords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (jsonCoords == null) {
      throw new UnmarshallException("coordinates missing");
    }
    Coordinate[] coordinates = new Coordinate[jsonCoords.length()];
    for (int i = 0; i < jsonCoords.length(); i++) {
      JSONObject nextCoord = jsonCoords.getJSONObject(i);
      if (nextCoord == null) {
        throw new UnmarshallException("inner coordinate missing");
      }
      coordinates[i] = new Coordinate(nextCoord.getDouble("x"), nextCoord.getDouble("y"));
    }
View Full Code Here

    return geometry;
  }

  private Point createPoint(GeometryFactory factory, JSONObject jso) throws UnmarshallException {
    Point geometry;
    JSONArray jsonCoords = jso.getJSONArray(ATTRIBUTE_COORDINATES);
    if (jsonCoords == null) {
      throw new UnmarshallException("coordinates missing");
    }
    if (jsonCoords.length() != 1) {
      throw new UnmarshallException("wrong number of coordinates " + jsonCoords.length() + " for point");
    }
    JSONObject coord = jsonCoords.getJSONObject(0);
    if (coord == null) {
      throw new UnmarshallException("inner coordinate missing");
    }

    Coordinate coordinate = new Coordinate(coord.getDouble("x"), coord.getDouble("y"));
View Full Code Here

    return geometry;
  }

  private MultiPolygon createMultiPolygon(GeometryFactory factory, JSONObject jso)
      throws UnmarshallException {
    JSONArray polyArray = jso.getJSONArray("polygons");
    Polygon[] polygons = new Polygon[polyArray.length()];
    for (int i = 0; i < polygons.length; i++) {
      polygons[i] = createPolygon(factory, polyArray.getJSONObject(i));
    }
    return factory.createMultiPolygon(polygons);
  }
View Full Code Here

    return factory.createMultiPolygon(polygons);
  }

  private Geometry createMultiLineString(GeometryFactory factory, JSONObject jso)
      throws UnmarshallException {
    JSONArray lineArray = jso.getJSONArray("lineStrings");
    LineString[] lineStrings = new LineString[lineArray.length()];
    for (int i = 0; i < lineArray.length(); i++) {
      lineStrings[i] = createLineString(factory, lineArray.getJSONObject(i));
    }
    return factory.createMultiLineString(lineStrings);
  }
View Full Code Here

    }
  }

  private JSONObject fromPoint(Point p) {
    JSONObject jso = new JSONObject();
    JSONArray coordinates = new JSONArray();
    PrecisionModel precisionmodel = p.getPrecisionModel();
    coordinates.put(precisionmodel.makePrecise(p.getX()));
    coordinates.put(precisionmodel.makePrecise(p.getY()));
    putBasics(jso, p);
    jso.put(ATTRIBUTE_COORDINATES, coordinates);
    return jso;
  }
View Full Code Here

    return jso;
  }

  private JSONObject fromMultiPoint(MultiPoint mp) {
    JSONObject jso = new JSONObject();
    JSONArray polys = new JSONArray();
    for (int i = 0; i < mp.getNumGeometries(); i++) {
      polys.put(fromPoint((Point) mp.getGeometryN(i)));
    }
    jso.put("points", polys);
    putBasics(jso, mp);
    return jso;
  }
View Full Code Here

TOP

Related Classes of org.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.