/** * Reads a GeometryCollection from GeoJSON. * * @param input The input. See {@link GeoJSONUtil#toReader(Object)} for details. * @return The geometry collection. * @throws IOException In the event of a parsing error or if the input json is invalid. */ public GeometryCollection readGeometryCollection(Object input) throws IOException { return parse(new GeometryCollectionHandler(factory), input); }
@Override public boolean primitive(Object value) throws ParseException, IOException { /* handle special case of "type" belonging to one of the collection's geometries * being found after "coordinates" for that geometry. */ if (geoms != null && value instanceof String && delegate == UNINITIALIZED) { delegateClass = lookupDelegate(value.toString()); if (proxy != null) { delegate = createDelegate(delegateClass, new Object[] {factory}); delegateClass = null; proxy.replay(delegate); proxy = null; } } else { return super.primitive(value); } return true; }
@Override public boolean endObjectEntry() throws ParseException, IOException { if (delegateClass != null) { delegate = createDelegate(delegateClass, new Object[] {factory}); delegateClass = null; } return true; }
@Override public boolean primitive(Object value) throws ParseException, IOException { if (geoms != null && delegate == UNINITIALIZED) { //this is the "type" of a member geometry delegateClass = lookupDelegate(value.toString()); } else { return super.primitive(value); } return true; }
@Override public boolean endObjectEntry() throws ParseException, IOException { if (delegateClass != null) { delegate = createDelegate(delegateClass, new Object[]{factory}); delegateClass = null; } return true; }
@Override public boolean startObjectEntry(String key) throws ParseException, IOException { if ("type".equals(key) && (delegate == NULL || delegate == proxy)) { delegate = UNINITIALIZED; return true; } else if ("coordinates".equals(key) && delegate == NULL) { // case of specifying coordinates before the actual geometry type, create a proxy // handler that will simply track calls until the type is actually specified proxy = new RecordingHandler(); delegate = proxy; return super.startObjectEntry(key); } else if ("geometries".equals(key) && delegate == NULL) { // geometry collection without type property first delegate = new GeometryCollectionHandler(factory); return super.startObjectEntry(key); } else { return super.startObjectEntry(key); } }
/** * Reads a GeometryCollection from GeoJSON. * * @param input The input. See {@link GeoJSONUtil#toReader(Object)} for details. * * @return The geometry collection. * * @throws IOException In the event of a parsing error or if the input json is invalid. */ public GeometryCollection readGeometryCollection(Object input) throws IOException { return parse(new GeometryCollectionHandler(factory), input); }