From aef37144c9fec7f7be1e048e13117008f6cba11b Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Mon, 24 Jan 2022 13:38:30 +0100 Subject: [PATCH] fix: Raster receive!! --- speckle/converter/geometry/__init__.py | 3 --- speckle/converter/layers.py | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/speckle/converter/geometry/__init__.py b/speckle/converter/geometry/__init__.py index 8a3f8add..60799ea6 100644 --- a/speckle/converter/geometry/__init__.py +++ b/speckle/converter/geometry/__init__.py @@ -65,9 +65,6 @@ def convertToNative(base: Base) -> Union[QgsGeometry, None]: return converted - - - def multiPointToNative(items: List[Point]): pts = QgsMultiPoint() for item in items: diff --git a/speckle/converter/layers.py b/speckle/converter/layers.py index f720c912..672e7795 100644 --- a/speckle/converter/layers.py +++ b/speckle/converter/layers.py @@ -13,6 +13,7 @@ from speckle.converter.geometry import (convertToSpeckle, transform) from speckle.converter.geometry.mesh import rasterToMesh +from speckle.converter.geometry.point import pointToNative from speckle.logging import logger from specklepy.objects import Base @@ -336,12 +337,6 @@ def rasterFeatureToSpeckle(selectedLayer, projectCRS, project): if(b['displayValue'] is None): b['displayValue'] = [] b['displayValue'].append(mesh) - - # testing, only for receiving layers - source_folder = selectedLayer.source().replace(selectedLayer.source().split('/')[len(selectedLayer.source().split('/'))-1],"") - epsg = int(str(projectCRS).split(":")[len(str(projectCRS).split(":"))-1].split(">")[0]) - receiveRaster(project, source_folder, selectedLayer.name(), epsg, rasterDimensions, rasterBandCount, rasterBandVals, reprojectedPt, rasterResXY) - return b @@ -376,13 +371,12 @@ def receiveRaster(project, source_folder, name, epsg, rasterDimensions, bands, r ds = None #add the new raster to the QGIS interface #rlayer = iface.addRasterLayer(fn) - raster_layer = QgsRasterLayer(fn, 'Layer_name', 'gdal') + raster_layer = QgsRasterLayer(fn, name, 'gdal') project.addMapLayer(raster_layer) -class RasterLayer(Base, speckle_type="Objects.Geometry." + "RasterLayer", chunkable={"Raster": 1000}, detachable={"Raster"}): +class RasterLayer(Base, speckle_type="Objects.Geometry." + "RasterLayer", chunkable={"Raster": 1000, "BandNames": 100}, detachable={"Raster"}): Raster: Optional[List[str]] = None - @ classmethod def from_list(cls, args: List[Any]) -> "RasterLayer": @@ -493,8 +487,18 @@ def vectorLayerToNative(layer: Layer): return vl def rasterLayerToNative(layer: Layer): - rl = QgsRasterLayer("Speckle", layer.name, "memory", QgsRasterLayer.LayerOptions()) + # testing, only for receiving layers + source_folder = QgsProject.instance().absolutePath() + project = QgsProject.instance() + projectCRS = QgsCoordinateReferenceSystem.fromWkt(layer.crs.wkt) + epsg = int(str(projectCRS).split(":")[len(str(projectCRS).split(":"))-1].split(">")[0]) + + feat = layer.features[0] + bandNames = feat["Band names"] + bandValues = [feat["@(10000)" + name + "_values"] for name in bandNames] + receiveRaster(project, source_folder, layer.name, epsg, [feat["X pixels"],feat["Y pixels"]], feat["Band count"], bandValues, pointToNative(feat["displayValue"][0]), [feat["X resolution"],feat["Y resolution"]]) + return None def get_type(type_name):