Skip to content

Commit

Permalink
preserve native raster units
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jun 13, 2023
1 parent 38627a7 commit ef97279
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
10 changes: 5 additions & 5 deletions speckle/converter/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ def layerToSpeckle(selectedLayer: Union[QgsVectorLayer, QgsRasterLayer], project
crs = selectedLayer.crs()

units_proj = plugin.dataStorage.currentUnits
units_layer = QgsUnitTypes.encodeUnit(crs.mapUnits())
print(units_layer)
units_layer_native = str(QgsUnitTypes.encodeUnit(crs.mapUnits()))

units_layer = units_layer_native
if crs.isGeographic(): units_layer = "m" ## specklepy.logging.exceptions.SpeckleException: SpeckleException: Could not understand what unit degrees is referring to. Please enter a valid unit (eg ['mm', 'cm', 'm', 'in', 'ft', 'yd', 'mi']).
layerObjs = []

# Convert CRS to speckle, use the projectCRS
print(projectCRS.toWkt())
speckleReprojectedCrs = CRS(name=projectCRS.authid(), wkt=projectCRS.toWkt(), units=units_proj)
layerCRS = CRS(name=crs.authid(), wkt=crs.toWkt(), units=units_layer)
layerCRS = CRS(name=crs.authid(), wkt=crs.toWkt(), units=units_layer, units_native = units_layer_native)

renderer = selectedLayer.renderer()
layerRenderer = rendererToSpeckle(renderer)
Expand Down Expand Up @@ -384,7 +384,7 @@ def addBimMainThread(plugin, geomType, layerName, streamBranch, newFields, geomL


crs = project.crs() #QgsCoordinateReferenceSystem.fromWkt(layer.crs.wkt)
plugin.dataStorage.currentUnits = QgsUnitTypes.encodeUnit(crs.mapUnits())
plugin.dataStorage.currentUnits = str(QgsUnitTypes.encodeUnit(crs.mapUnits()))
if plugin.dataStorage.currentUnits is None or plugin.dataStorage.currentUnits == 'degrees':
plugin.dataStorage.currentUnits = 'm'

Expand Down Expand Up @@ -595,7 +595,7 @@ def addCadMainThread(plugin, geomType, newName, streamBranch, newFields, geomLis
#################################################

crs = project.crs() #QgsCoordinateReferenceSystem.fromWkt(layer.crs.wkt)
plugin.dataStorage.currentUnits = QgsUnitTypes.encodeUnit(crs.mapUnits())
plugin.dataStorage.currentUnits = str(QgsUnitTypes.encodeUnit(crs.mapUnits()))
if plugin.dataStorage.currentUnits is None or plugin.dataStorage.currentUnits == 'degrees':
plugin.dataStorage.currentUnits = 'm'
#authid = trySaveCRS(crs, streamBranch)
Expand Down
2 changes: 1 addition & 1 deletion speckle/converter/layers/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pyqt_ui.logger import logToUser

def featureToSpeckle(fieldnames: List[str], f: QgsFeature, sourceCRS: QgsCoordinateReferenceSystem, targetCRS: QgsCoordinateReferenceSystem, project: QgsProject, selectedLayer: QgsVectorLayer or QgsRasterLayer, dataStorage = None):
#b = Base(units = dataStorage.currentUnits)

if dataStorage is None: return
units = dataStorage.currentUnits
try:
Expand Down
17 changes: 2 additions & 15 deletions speckle_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@
from qgis.core import (Qgis, QgsProject, QgsLayerTreeLayer,
QgsLayerTreeGroup, QgsCoordinateReferenceSystem,
QgsRasterLayer, QgsVectorLayer,
QgsUnitTypes, QgsWkbTypes,
QgsLayerTree, QgsLayerTreeGroup, QgsLayerTreeNode, QgsLayerTreeLayer,
QgsFields,
QgsSingleSymbolRenderer, QgsCategorizedSymbolRenderer,
QgsRendererCategory,
QgsSymbol)
QgsUnitTypes)
from qgis.PyQt.QtCore import QCoreApplication, QSettings, Qt, QTranslator, QRect
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QApplication, QAction, QDockWidget, QVBoxLayout, QWidget
from qgis.PyQt import QtWidgets
from qgis import PyQt

from PyQt5.QtGui import QColor

import sip

from specklepy.core.api import operations
Expand Down Expand Up @@ -76,9 +69,6 @@
# Import the code for the dialog
from speckle.utils.validation import tryGetStream, validateBranch, validateCommit, validateStream, validateTransport

#import concurrent.futures
#from concurrent.futures import ThreadPoolExecutor

SPECKLE_COLOR = (59,130,246)
SPECKLE_COLOR_LIGHT = (69,140,255)

Expand All @@ -100,12 +90,9 @@ class SpeckleQGIS:
lat: float
lon: float

#default_account: Account
accounts: List[Account]
#active_account: Account

theads_total: int

dataStorage: DataStorage

def __init__(self, iface):
Expand Down Expand Up @@ -434,7 +421,7 @@ def onSend(self, message: str):
self.dataStorage.all_layers = getAllLayers(root)
self.dockwidget.mappingSendDialog.populateSavedTransforms(self.dataStorage)

units = QgsUnitTypes.encodeUnit(projectCRS.mapUnits())
units = str(QgsUnitTypes.encodeUnit(projectCRS.mapUnits()))
if units is None or units == 'degrees': units = 'm'
self.dataStorage.currentUnits = units

Expand Down

0 comments on commit ef97279

Please sign in to comment.