Search in sources :

Example 1 with GeometryReader

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());
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryReader(com.revolsys.geometry.io.GeometryReader) ClockDirection(com.revolsys.geometry.model.ClockDirection)

Example 2 with GeometryReader

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();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryReader(com.revolsys.geometry.io.GeometryReader)

Example 3 with GeometryReader

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) InputStream(java.io.InputStream) MediaType(org.springframework.http.MediaType) Charset(java.nio.charset.Charset) IOException(java.io.IOException) GeometryReaderFactory(com.revolsys.geometry.io.GeometryReaderFactory) GeometryReader(com.revolsys.geometry.io.GeometryReader) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) InputStreamResource(com.revolsys.spring.resource.InputStreamResource)

Aggregations

GeometryReader (com.revolsys.geometry.io.GeometryReader)3 Geometry (com.revolsys.geometry.model.Geometry)2 GeometryReaderFactory (com.revolsys.geometry.io.GeometryReaderFactory)1 ClockDirection (com.revolsys.geometry.model.ClockDirection)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 InputStreamResource (com.revolsys.spring.resource.InputStreamResource)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1