Package org.json

Examples of org.json.JSONObject


      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"));
    geometry.setCoordinates(new Coordinate[] {coordinate});
    return geometry;
  }
View Full Code Here


    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"));
    }
    geometry.setCoordinates(coordinates);
    return geometry;
  }
View Full Code Here

    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"));
    }
    coordinates = checkIfClosed(coordinates);
    geometry.setCoordinates(coordinates);
    return geometry;
  }
View Full Code Here

    geometry.setCoordinates(coordinates);
    return geometry;
  }

  private Geometry createPolygon(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONObject shell = json.getJSONObject("shell");
    if (shell == null) {
      throw new UnmarshallException("exterior ring is missing");
    }
    int len = 1;
    JSONArray holes = json.getJSONArray("holes");
View Full Code Here

  // MARSHALL: server-to-client serialization
  // -------------------------------------------------------------------------

  public Object marshall(SerializerState state, Object o) throws MarshallException {
    Geometry geometry = (Geometry) o;
    JSONObject json = null;
    if (geometry.getGeometryType().equals(Geometry.POINT)) {
      json = serializePoint(geometry);
    } else if (geometry.getGeometryType().equals(Geometry.LINE_STRING)) {
      json = serializeLineString(geometry);
    } else if (geometry.getGeometryType().equals(Geometry.LINEAR_RING)) {
View Full Code Here

    }
    return json;
  }

  private JSONObject serializePoint(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);
    putCoordinates(json, geometry);
    return json;
  }
View Full Code Here

    putCoordinates(json, geometry);
    return json;
  }

  private JSONObject serializeLineString(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);
    putCoordinates(json, geometry);
    return json;
  }
View Full Code Here

    putCoordinates(json, geometry);
    return json;
  }

  private JSONObject serializeLinearRing(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);
    putCoordinates(json, geometry);
    return json;
  }
View Full Code Here

    putCoordinates(json, geometry);
    return json;
  }

  private JSONObject serializePolygon(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);

    JSONObject shell = null;
    if (geometry.getGeometries() != null && geometry.getGeometries().length > 0) {
      Geometry exteriorRing = geometry.getGeometries()[0];
      exteriorRing.setGeometryType(Geometry.LINE_STRING);
      shell = serializeLinearRing(exteriorRing);
    }
View Full Code Here

    return json;
  }

  private JSONObject serializeMultiPoint(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);

    JSONArray points = null;
    if (geometry.getGeometries() != null && geometry.getGeometries().length > 0) {
      points = new JSONArray();
      for (int i = 0; i < geometry.getGeometries().length; i++) {
        points.put(serializePoint(geometry.getGeometries()[i]));
      }
    }
    json.put("points", points);
    return json;
  }
View Full Code Here

TOP

Related Classes of org.json.JSONObject

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.