Search in sources :

Example 16 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class RecordIoTestSuite method addWriteReadTest.

public static void addWriteReadTest(final TestSuite suite, final String prefix, final String fileExtension) {
    addGeometryTestSuites(suite, prefix, (geometryFactory, geometry, geometryDataType) -> {
        final String geometryTypeString = geometryDataType.toString();
        final File directory = new File("/tmp/revolsystest/io/" + fileExtension);
        final File file = new File(directory, geometryTypeString + "_" + geometryFactory.getAxisCount() + "_" + geometry.getVertexCount() + "." + fileExtension);
        file.delete();
        file.getParentFile().mkdirs();
        final PathResource resource = new PathResource(file);
        final RecordWriterFactory recordWriterFactory = IoFactory.factory(RecordWriterFactory.class, resource);
        final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(PathName.newPathName(geometryTypeString));
        if (recordWriterFactory.isCustomFieldsSupported()) {
            recordDefinition.addField("BOOLEAN", DataTypes.BOOLEAN, true);
            recordDefinition.addField("BYTE", DataTypes.BYTE, true);
            recordDefinition.addField("SHORT", DataTypes.SHORT, true);
            recordDefinition.addField("INT", DataTypes.INT, true);
            recordDefinition.addField("LONG", DataTypes.LONG, true);
            recordDefinition.addField("FLOAT", DataTypes.FLOAT, 4, 3, true);
            recordDefinition.addField("DOUBLE", DataTypes.DOUBLE, 10, 9, true);
            recordDefinition.addField("STRING", DataTypes.STRING, true);
        }
        if (recordWriterFactory.isGeometrySupported()) {
            recordDefinition.addField("GEOMETRY", geometryDataType, true);
        }
        recordDefinition.setGeometryFactory(geometryFactory);
        final ArrayRecord record = new ArrayRecord(recordDefinition);
        record.setValue("BOOLEAN", true);
        record.setValue("BYTE", Byte.MAX_VALUE);
        record.setValue("SHORT", Short.MAX_VALUE);
        record.setValue("INT", Integer.MAX_VALUE);
        record.setValue("LONG", 999999999999999999L);
        record.setValue("FLOAT", 6.789);
        record.setValue("DOUBLE", 1.234567890);
        record.setValue("STRING", "test");
        record.setGeometryValue(geometry);
        doRecordWriteTest(resource, record);
        doRecordReadTest(resource, record);
        doGeometryReadTest(resource, record);
    });
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) PathResource(com.revolsys.spring.resource.PathResource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) RecordWriterFactory(com.revolsys.record.io.RecordWriterFactory) File(java.io.File)

Example 17 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class RecordWriterPerformanceTest method writeRecords.

private static void writeRecords(final Path basePath, final RecordDefinition recordDefinition, final RecordWriterFactory writerFactory) {
    final String fileExtension = writerFactory.getFileExtensions().get(0);
    final Resource resource = new PathResource(basePath.resolve("records." + fileExtension));
    final Record record = newRecord(recordDefinition, 0);
    // Prime the code to avoid initialization in timings
    try {
        writeRecords(writerFactory, recordDefinition, resource, 1, record);
    } finally {
        resource.delete();
    }
    try {
        final long time = System.currentTimeMillis();
        final int numIterations = 1000000;
        writeRecords(writerFactory, recordDefinition, resource, numIterations, record);
        final long ellapsedTime = System.currentTimeMillis() - time;
        final long millis = ellapsedTime % 1000;
        final long seconds = ellapsedTime / 1000 % 60;
        final long minutes = ellapsedTime / 60000 % 60;
        System.out.println(writerFactory.getName() + "\t" + minutes + ":" + seconds + "." + millis + "\t" + resource.getFile().length());
    } finally {
        resource.delete();
    }
    for (int i = 0; i < 10; i++) {
        System.gc();
        synchronized (record) {
            try {
                record.wait(1000);
            } catch (final InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 18 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class Gdal method getDataset.

public static Dataset getDataset(final File file, final int mode) {
    if (isAvailable()) {
        final String path = file.getAbsolutePath();
        if (file.exists()) {
            final Dataset dataset = gdal.Open(path, mode);
            if (dataset == null) {
                throw new GdalException();
            } else {
                final Resource resource = new PathResource(file);
                setProjectionFromPrjFile(dataset, resource);
                final long modifiedTime = loadSettings(dataset, resource);
                return dataset;
            }
        } else {
            throw new IllegalArgumentException("File no found: " + path);
        }
    } else {
        throw new IllegalStateException("GDAL is not available");
    }
}
Also used : Dataset(org.gdal.gdal.Dataset) PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 19 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class ProjectFrame method loadProject.

protected void loadProject(final Path projectPath) {
    final PathResource resource = new PathResource(projectPath);
    this.project.readProject(this.project, resource);
    Invoke.later(() -> setTitle(this.project.getName() + " - " + this.frameTitle));
    final Object frameBoundsObject = this.project.getProperty("frameBounds");
    setBounds(frameBoundsObject, true);
    setVisible(true);
    final MapPanel mapPanel = getMapPanel();
    final BoundingBox initialBoundingBox = this.project.getInitialBoundingBox();
    final Viewport2D viewport = mapPanel.getViewport();
    if (!RectangleUtil.isEmpty(initialBoundingBox)) {
        this.project.setViewBoundingBoxAndGeometryFactory(initialBoundingBox);
        viewport.setBoundingBoxAndGeometryFactory(initialBoundingBox);
    }
    viewport.setInitialized(true);
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 20 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class Project method getProjectDirectory.

public Path getProjectDirectory() {
    if (this.resource == null) {
        final Path directory = getSaveAsDirectory();
        return directory;
    }
    if (this.resource instanceof PathResource) {
        final PathResource fileResource = (PathResource) this.resource;
        final File directory = fileResource.getFile();
        if (!directory.exists()) {
            directory.mkdirs();
        }
        if (directory.isDirectory()) {
            return directory.toPath();
        }
    } else if (this.resource instanceof PathResource) {
        final PathResource pathResource = (PathResource) this.resource;
        final Path directory = pathResource.getPath();
        if (!Files.exists(directory)) {
            try {
                Files.createDirectories(directory);
            } catch (final IOException e) {
                throw Exceptions.wrap(e);
            }
        }
        if (Files.isDirectory(directory)) {
            return directory;
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) PathResource(com.revolsys.spring.resource.PathResource) IOException(java.io.IOException) File(java.io.File)

Aggregations

PathResource (com.revolsys.spring.resource.PathResource)24 File (java.io.File)15 Resource (com.revolsys.spring.resource.Resource)7 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 Geometry (com.revolsys.geometry.model.Geometry)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)2 RecordWriter (com.revolsys.record.io.RecordWriter)2 Path (java.nio.file.Path)2 JFileChooser (javax.swing.JFileChooser)2 LasPointCloud (com.revolsys.elevation.cloud.las.LasPointCloud)1 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)1 PathName (com.revolsys.io.PathName)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 RecordWriterFactory (com.revolsys.record.io.RecordWriterFactory)1