use of com.revolsys.geometry.io.GeometryReader in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method doGeometryReadTest.
private static void doGeometryReadTest(final PathResource resource, final ArrayRecord record) {
if (GeometryReader.isReadable(resource)) {
try (GeometryReader geometryReader = GeometryReader.newGeometryReader(resource)) {
final ClockDirection polygonRingDirection = geometryReader.getPolygonRingDirection();
final List<Geometry> geometries = geometryReader.toList();
Assert.assertEquals("Geometry Count", 1, geometries.size());
final Geometry expectedGeometry = record.getGeometry();
final Geometry actualGeometry = geometries.get(0);
assertGeometry(polygonRingDirection, expectedGeometry, actualGeometry);
}
} else {
Logs.debug(RecordIoTestSuite.class, "Reading geometry not supported for: " + resource.getFileNameExtension());
}
}
use of com.revolsys.geometry.io.GeometryReader in project com.revolsys.open by revolsys.
the class GeometryRecordReader method closeDo.
@Override
protected void closeDo() {
final Iterator<Geometry> geometryIterator = this.geometryIterator;
this.geometryIterator = null;
if (geometryIterator instanceof BaseCloseable) {
final BaseCloseable closeable = (BaseCloseable) geometryIterator;
closeable.close();
}
final GeometryReader geometryReader = this.geometryReader;
this.geometryReader = null;
if (geometryReader != null) {
geometryReader.close();
}
super.closeDo();
}
use of com.revolsys.geometry.io.GeometryReader in project com.revolsys.open by revolsys.
the class GeometryReaderHttpMessageConverter method read.
@Override
public GeometryReader read(final Class<? extends GeometryReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final GeometryReaderFactory readerFactory = IoFactory.factoryByMediaType(GeometryReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final InputStreamResource resource = new InputStreamResource("geometryInput", body);
final GeometryReader reader = readerFactory.newGeometryReader(resource);
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
Aggregations