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();
}
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);
}
}
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());
}
}
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;
}
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);
}
}
Aggregations