Skip to content

Commit

Permalink
fix: Raster receive!!
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne committed Jan 24, 2022
1 parent 9a30a3e commit aef3714
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 0 additions & 3 deletions speckle/converter/geometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def convertToNative(base: Base) -> Union[QgsGeometry, None]:

return converted




def multiPointToNative(items: List[Point]):
pts = QgsMultiPoint()
for item in items:
Expand Down
24 changes: 14 additions & 10 deletions speckle/converter/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit aef3714

Please sign in to comment.