Search in sources :

Example 36 with Resource

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

the class Project method readBaseMapsLayers.

public BaseMapLayerGroup readBaseMapsLayers(final Project rootProject, final Resource resource) {
    final Resource baseMapsResource = resource.newChildResource("Base Maps");
    final Resource layerGroupResource = baseMapsResource.newChildResource("rgLayerGroup.rgobject");
    if (layerGroupResource.exists()) {
        final Resource oldResource = Resource.setBaseResource(baseMapsResource);
        try {
            final Map<String, Object> properties = Json.toMap(layerGroupResource);
            this.baseMapLayers.loadLayers(rootProject, properties);
            boolean hasVisible = false;
            if (this.baseMapLayers != null) {
                for (final Layer layer : this.baseMapLayers) {
                    if (hasVisible) {
                        layer.setVisible(false);
                    } else {
                        hasVisible = layer.isVisible();
                    }
                }
            }
        } finally {
            Resource.setBaseResource(oldResource);
        }
    }
    return this.baseMapLayers;
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 37 with Resource

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

the class PointCloudLayer method cancelChanges.

public void cancelChanges() {
    if (this.pointCloud == null && this.resource != null) {
        PointCloud<?> pointCloud = null;
        final Resource pointCloudResource = Resource.getResource(this.url);
        if (pointCloudResource.exists()) {
            try {
                pointCloud = PointCloud.newPointCloud(pointCloudResource);
                if (pointCloud == null) {
                    Logs.error(PointCloudLayer.class, "Cannot load: " + this.url);
                }
            } catch (final RuntimeException e) {
                Logs.error(PointCloudLayer.class, "Unable to load: " + this.url, e);
            }
        } else {
            Logs.error(PointCloudLayer.class, "URL does not exist: " + this.url);
        }
        setPointCloud(pointCloud);
    } else {
    // this.pointCloud.cancelChanges();
    }
    firePropertyChange("hasChanges", true, false);
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Example 38 with Resource

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

the class TriangulatedIrregularNetwork method forEachTriangle.

static boolean forEachTriangle(final Object source, final MapEx properties, final TriangleConsumer action) {
    final TriangulatedIrregularNetworkReadFactory factory = IoFactory.factory(TriangulatedIrregularNetworkReadFactory.class, source);
    if (factory == null) {
        return false;
    } else {
        final Resource resource = factory.getZipResource(source);
        factory.forEachTriangle(resource, properties, action);
        return true;
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Example 39 with Resource

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

the class ScaledIntegerGriddedDigitalElevation method getElevationInterpolated.

public static double getElevationInterpolated(final Resource baseResource, final int coordinateSystemId, final int gridCellSize, final int gridSize, final String fileExtension, final double x, final double y) {
    final int gridTileSize = gridSize * gridCellSize;
    final int tileX = CustomRectangularMapGrid.getGridFloor(0.0, gridTileSize, x);
    final int tileY = CustomRectangularMapGrid.getGridFloor(0.0, gridTileSize, y);
    final Resource resource = RectangularMapGrid.getTileResource(baseResource, "dem", coordinateSystemId, Integer.toString(gridTileSize), tileX, tileY, fileExtension);
    if (resource.exists()) {
        try {
            final int gridCellX = GriddedElevationModel.getGridCellX(tileX, gridCellSize, x);
            final int gridCellY = GriddedElevationModel.getGridCellY(tileY, gridCellSize, y);
            final int elevationByteSize = 4;
            final int offset = HEADER_SIZE + (gridCellY * gridSize + gridCellX) * elevationByteSize;
            int elevation;
            if (resource.isFile()) {
                final Path path = resource.toPath();
                try (SeekableByteChannel byteChannel = Files.newByteChannel(path, StandardOpenOption.READ)) {
                    byteChannel.position(offset);
                    final ByteBuffer bytes = ByteBuffer.allocate(4);
                    byteChannel.read(bytes);
                    elevation = bytes.getInt(0);
                } catch (final IOException e) {
                    throw Exceptions.wrap("Unable to read: " + resource, e);
                }
            } else {
                try (DataInputStream in = resource.newBufferedInputStream(DataInputStream::new)) {
                    in.skip(offset);
                    elevation = in.readInt();
                } catch (final IOException e) {
                    throw Exceptions.wrap("Unable to read: " + resource, e);
                }
            }
            return elevation;
        } catch (final ClassCastException e) {
            throw new IllegalArgumentException(fileExtension + " not supported");
        }
    }
    return Double.NaN;
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) Resource(com.revolsys.spring.resource.Resource) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer)

Example 40 with Resource

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

the class TriangulatedIrregularNetworkWriter method newTriangulatedIrregularNetworkWriter.

static TriangulatedIrregularNetworkWriter newTriangulatedIrregularNetworkWriter(final Object target, final Map<String, ? extends Object> properties) {
    final TriangulatedIrregularNetworkWriterFactory factory = IoFactory.factory(TriangulatedIrregularNetworkWriterFactory.class, target);
    if (factory == null) {
        return null;
    } else {
        final Resource resource = Resource.getResource(target);
        final TriangulatedIrregularNetworkWriter writer = factory.newTriangulatedIrregularNetworkWriter(resource);
        writer.setProperties(properties);
        return writer;
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3