Package org.json

Examples of org.json.JSONArray


  }

  private JSONObject fromLineString(LineString ls) {
    PrecisionModel precisionmodel = ls.getPrecisionModel();
    JSONObject jso = new JSONObject();
    JSONArray coordinates = new JSONArray();
    for (int i = 0; i < ls.getCoordinates().length; i++) {
      coordinates.put(precisionmodel.makePrecise(ls.getCoordinates()[i].x));
      coordinates.put(precisionmodel.makePrecise(ls.getCoordinates()[i].y));
    }
    putBasics(jso, ls);
    jso.put(ATTRIBUTE_COORDINATES, coordinates);
    return jso;
  }
View Full Code Here


  }

  private JSONObject fromPolygon(Polygon pg) {
    JSONObject jso = new JSONObject();
    JSONObject shell = fromLineString(pg.getExteriorRing());
    JSONArray holes = new JSONArray();
    for (int i = 0; i < pg.getNumInteriorRing(); i++) {
      holes.put(fromLineString(pg.getInteriorRingN(i)));
    }
    jso.put("shell", shell);
    jso.put("holes", holes);
    putBasics(jso, pg);
    return jso;
View Full Code Here

    return jso;
  }

  private JSONObject fromMultiPolygon(MultiPolygon mp) {
    JSONObject jso = new JSONObject();
    JSONArray polys = new JSONArray();
    for (int i = 0; i < mp.getNumGeometries(); i++) {
      polys.put(fromPolygon((Polygon) mp.getGeometryN(i)));
    }
    jso.put("polygons", polys);
    putBasics(jso, mp);
    return jso;
  }
View Full Code Here

    return jso;
  }

  private JSONObject fromMultiLineString(MultiLineString ml) {
    JSONObject jso = new JSONObject();
    JSONArray polys = new JSONArray();
    for (int i = 0; i < ml.getNumGeometries(); i++) {
      polys.put(fromLineString((LineString) ml.getGeometryN(i)));
    }
    jso.put("lineStrings", polys);
    putBasics(jso, ml);
    return jso;
  }
View Full Code Here

    if (!(type.equals(Geometry.POINT) || type.equals(Geometry.LINE_STRING) || type.equals(Geometry.POLYGON)
        || type.equals(Geometry.LINEAR_RING) || type.equals(Geometry.MULTI_LINE_STRING) ||
        type.equals(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

    }
    return geometry;
  }

  private Geometry createPoint(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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

    geometry.setCoordinates(new Coordinate[] {coordinate});
    return geometry;
  }

  private Geometry createLineString(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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

    geometry.setCoordinates(coordinates);
    return geometry;
  }

  private Geometry createLinearRing(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray jsonCoords = json.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

    JSONObject shell = json.getJSONObject("shell");
    if (shell == null) {
      throw new UnmarshallException("exterior ring is missing");
    }
    int len = 1;
    JSONArray holes = json.getJSONArray("holes");
    if (holes != null) {
      len += holes.length();
    }
    Geometry[] geometries = new Geometry[len];
    Geometry linearRing = new Geometry("LinearRing", geometry.getSrid(), geometry.getPrecision());
    geometries[0] = createLinearRing(linearRing, shell);
    if (holes != null) {
      for (int i = 1; i < len; i++) {
        geometries[i] = createLinearRing(linearRing, holes.getJSONObject(i - 1));
      }
    }
    geometry.setGeometries(geometries);
    return geometry;
  }
View Full Code Here

    geometry.setGeometries(geometries);
    return geometry;
  }

  private Geometry createMultiPoint(Geometry geometry, JSONObject json) throws UnmarshallException {
    JSONArray points = json.getJSONArray("points");
    if (points == null) {
      throw new UnmarshallException("points are missing");
    }
    Geometry[] geometries = new Geometry[points.length()];
    for (int i = 0; i < points.length(); i++) {
      Geometry point = new Geometry(Geometry.POINT, geometry.getSrid(), geometry.getPrecision());
      geometries[i] = createPoint(point, points.getJSONObject(i));
    }
    geometry.setGeometries(geometries);
    return geometry;
  }
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.