Search in sources :

Example 6 with JsonParser

use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.

the class GeoJsonGeometryReader method getNext.

@Override
protected Geometry getNext() throws NoSuchElementException {
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToAttribute();
        if (GeoJson.TYPE.equals(fieldName)) {
            this.in.next();
            final String geometryType = this.in.getCurrentValue();
            if (GeoJson.GEOMETRY_TYPE_NAMES.contains(geometryType)) {
                return readGeometry();
            }
        } else if (GeoJson.CRS.equals(fieldName)) {
            this.in.next();
            this.geometryFactory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endDocument);
    throw new NoSuchElementException();
}
Also used : LineString(com.revolsys.geometry.model.LineString) NoSuchElementException(java.util.NoSuchElementException) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 7 with JsonParser

use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.

the class GeoJsonGeometryReader method readLineString.

private LineString readLineString(final boolean cogo) {
    LineString points = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            points = readCoordinatesList(cogo, false);
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    if (points == null) {
        return factory.lineString();
    } else {
        final int axisCount = points.getAxisCount();
        final GeometryFactory geometryFactory = factory.convertAxisCount(axisCount);
        return geometryFactory.lineString(points);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 8 with JsonParser

use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.

the class GeoJsonGeometryReader method readCoordinatesListCoordinates.

/**
 * Read one points coordinates and add them to the list of coordinate values.
 *
 * @param values The list to add the points coordinates to.
 * @return The dimension of the coordinate read.
 */
private int readCoordinatesListCoordinates(final List<Double> values) {
    int numAxis = 0;
    if (this.in.getEvent() == EventType.startArray || this.in.hasNext() && this.in.next() == EventType.startArray) {
        EventType event = this.in.getEvent();
        do {
            final JsonParser parser = this.in;
            final Object value = parser.getValue();
            if (value instanceof EventType) {
                event = (EventType) value;
            } else if (value instanceof Number) {
                values.add(((Number) value).doubleValue());
                numAxis++;
                event = this.in.next();
            } else {
                throw new IllegalArgumentException("Expecting number, not: " + value);
            }
        } while (event == EventType.comma);
        if (event != EventType.endArray) {
            throw new IllegalStateException("Exepecting end array, not: " + event);
        }
        return numAxis;
    } else {
        throw new IllegalStateException("Exepecting start array, not: " + this.in.getEvent());
    }
}
Also used : EventType(com.revolsys.record.io.format.json.JsonParser.EventType) Point(com.revolsys.geometry.model.Point) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 9 with JsonParser

use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.

the class GeoJsonGeometryReader method readCoordinateSystem.

private GeometryFactory readCoordinateSystem() {
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.PROPERTIES.equals(fieldName)) {
            final JsonParser parser1 = this.in;
            final Map<String, Object> properties = parser1.getMap();
            final String name = (String) properties.get("name");
            if (name != null) {
                if (name.startsWith(GeoJson.URN_OGC_DEF_CRS_EPSG)) {
                    final int srid = Integer.parseInt(name.substring(GeoJson.URN_OGC_DEF_CRS_EPSG.length()));
                    factory = GeometryFactory.floating3d(srid);
                } else if (name.startsWith(GeoJson.EPSG)) {
                    final int srid = Integer.parseInt(name.substring(GeoJson.EPSG.length()));
                    factory = GeometryFactory.floating3d(srid);
                }
            }
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    return factory;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 10 with JsonParser

use of com.revolsys.record.io.format.json.JsonParser in project com.revolsys.open by revolsys.

the class GeoJsonGeometryReader method readPointCoordinatesList.

private LineString readPointCoordinatesList() {
    final JsonParser parser = this.in;
    final double[] values = parser.getDoubleArray();
    if (values == null) {
        return null;
    } else {
        return new LineStringDouble(values.length, values);
    }
}
Also used : JsonParser(com.revolsys.record.io.format.json.JsonParser) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Aggregations

JsonParser (com.revolsys.record.io.format.json.JsonParser)13 Point (com.revolsys.geometry.model.Point)10 LineString (com.revolsys.geometry.model.LineString)9 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)8 Geometry (com.revolsys.geometry.model.Geometry)3 EventType (com.revolsys.record.io.format.json.JsonParser.EventType)3 NoSuchElementException (java.util.NoSuchElementException)3 MapEx (com.revolsys.collection.map.MapEx)2 Record (com.revolsys.record.Record)2 ArrayList (java.util.ArrayList)2 Polygon (com.revolsys.geometry.model.Polygon)1 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)1 List (java.util.List)1