Search in sources :

Example 1 with XbaseRecordReader

use of com.revolsys.record.io.format.xbase.XbaseRecordReader in project com.revolsys.open by revolsys.

the class ShapefileRecordReader method initDo.

@Override
protected synchronized void initDo() {
    if (this.in == null) {
        try {
            try {
                if (this.resource.isFile()) {
                    final File file = this.resource.getFile();
                    this.in = new LittleEndianRandomAccessFile(file, "r");
                } else {
                    this.in = new EndianInputStream(this.resource.getInputStream());
                }
            } catch (final IllegalArgumentException | UnsupportedOperationException e) {
                this.in = new EndianInputStream(this.resource.getInputStream());
            }
            final Resource xbaseResource = this.resource.newResourceChangeExtension("dbf");
            if (xbaseResource != null && xbaseResource.exists()) {
                this.xbaseRecordReader = new XbaseRecordReader(xbaseResource, this.recordFactory, () -> updateRecordDefinition());
                this.xbaseRecordReader.setTypeName(this.typeName);
                this.xbaseRecordReader.setCloseFile(this.closeFile);
            }
            loadHeader();
            int axisCount;
            switch(this.shapeType) {
                // 1
                case ShapefileConstants.POINT_SHAPE:
                // 3
                case ShapefileConstants.POLYLINE_SHAPE:
                // 5
                case ShapefileConstants.POLYGON_SHAPE:
                case // 8
                ShapefileConstants.MULTI_POINT_SHAPE:
                    axisCount = 2;
                    break;
                // 9
                case ShapefileConstants.POINT_Z_SHAPE:
                // 10
                case ShapefileConstants.POLYLINE_Z_SHAPE:
                // 19
                case ShapefileConstants.POLYGON_Z_SHAPE:
                case // 20
                ShapefileConstants.MULTI_POINT_Z_SHAPE:
                    axisCount = 3;
                    break;
                // 11
                case ShapefileConstants.POINT_ZM_SHAPE:
                // 13
                case ShapefileConstants.POLYLINE_ZM_SHAPE:
                // 15
                case ShapefileConstants.POLYGON_ZM_SHAPE:
                // 18
                case ShapefileConstants.MULTI_POINT_ZM_SHAPE:
                // 21
                case ShapefileConstants.POINT_M_SHAPE:
                // 23
                case ShapefileConstants.POLYLINE_M_SHAPE:
                // 25
                case ShapefileConstants.POLYGON_M_SHAPE:
                case // 28
                ShapefileConstants.MULTI_POINT_M_SHAPE:
                    axisCount = 4;
                    break;
                default:
                    throw new RuntimeException("Unknown shape type:" + this.shapeType);
            }
            this.geometryFactory = getProperty(IoConstants.GEOMETRY_FACTORY);
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(this.resource, axisCount);
            }
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(0, axisCount);
            }
            setProperty(IoConstants.GEOMETRY_FACTORY, this.geometryFactory);
            if (this.xbaseRecordReader != null) {
                this.xbaseRecordReader.hasNext();
            }
            if (this.recordDefinition == null) {
                this.recordDefinition = Records.newGeometryRecordDefinition();
            }
            this.recordDefinition.setGeometryFactory(this.geometryFactory);
        } catch (final IOException e) {
            throw new RuntimeException("Error initializing mappedFile " + this.resource, e);
        }
    }
}
Also used : EndianInputStream(com.revolsys.io.endian.EndianInputStream) Resource(com.revolsys.spring.resource.Resource) XbaseRecordReader(com.revolsys.record.io.format.xbase.XbaseRecordReader) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile) IOException(java.io.IOException) File(java.io.File) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile)

Aggregations

EndianInputStream (com.revolsys.io.endian.EndianInputStream)1 LittleEndianRandomAccessFile (com.revolsys.io.endian.LittleEndianRandomAccessFile)1 XbaseRecordReader (com.revolsys.record.io.format.xbase.XbaseRecordReader)1 Resource (com.revolsys.spring.resource.Resource)1 File (java.io.File)1 IOException (java.io.IOException)1