Search in sources :

Example 1 with JsonParser

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

the class GeoJsonGeometryReader method readMultiPolygon.

private Geometry readMultiPolygon(final boolean cogo) {
    final List<Polygon> polygons = new ArrayList<>();
    List<List<LineString>> polygonRings = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            polygonRings = readCoordinatesListListList(cogo);
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    int axisCount = 2;
    if (polygonRings != null) {
        for (final List<LineString> rings : polygonRings) {
            for (final LineString points : rings) {
                axisCount = Math.max(axisCount, points.getAxisCount());
            }
            factory = factory.convertAxisCount(axisCount);
            final Polygon polygon = factory.polygon(rings);
            polygons.add(polygon);
        }
    }
    return factory.polygonal(polygons);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LineString(com.revolsys.geometry.model.LineString) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 2 with JsonParser

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

the class GeoJsonGeometryReader method readMultiPoint.

private Geometry readMultiPoint() {
    List<LineString> pointsList = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            pointsList = readPointCoordinatesListList();
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    int axisCount = 2;
    for (final LineString points : pointsList) {
        axisCount = Math.max(axisCount, points.getAxisCount());
    }
    factory = factory.convertAxisCount(axisCount);
    return factory.punctual(pointsList);
}
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 3 with JsonParser

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

the class GeoJsonGeometryReader method readMultiLineString.

private Geometry readMultiLineString(final boolean cogo) {
    List<LineString> lineStrings = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            lineStrings = readCoordinatesListList(cogo, false);
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    int axisCount = 2;
    for (final LineString points : lineStrings) {
        axisCount = Math.max(axisCount, points.getAxisCount());
    }
    factory = factory.convertAxisCount(axisCount);
    return factory.lineal(lineStrings);
}
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 4 with JsonParser

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

the class GeoJsonGeometryReader method readGeometryCollection.

private Geometry readGeometryCollection() {
    List<Geometry> geometries = new ArrayList<>();
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.GEOMETRIES.equals(fieldName)) {
            geometries = readGeometryList();
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    return factory.geometry(geometries);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LineString(com.revolsys.geometry.model.LineString) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 5 with JsonParser

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

the class GeoJsonGeometryReader method readPoint.

private Point readPoint() {
    LineString coordinates = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            coordinates = readPointCoordinatesList();
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    if (coordinates == null) {
        return factory.point();
    } else {
        final int axisCount = coordinates.getAxisCount();
        final GeometryFactory geometryFactory = factory.convertAxisCount(axisCount);
        return geometryFactory.point(coordinates);
    }
}
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)

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