Skip to content

Commit 6ae3bc1

Browse files
Fix: revert building qgs Table
1 parent 83c4dfa commit 6ae3bc1

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

loopstructural/processing/algorithms/sampler.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
7777
QgsProcessingParameterEnum(
7878
self.INPUT_SAMPLER_TYPE,
7979
"SAMPLER_TYPE",
80-
["Decimator", "Spacing"],
80+
["Decimator (Point Geometry Data)",
81+
"Spacing (Line Geometry Data)"],
8182
defaultValue=0
8283
)
8384
)
@@ -112,7 +113,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
112113
self.addParameter(
113114
QgsProcessingParameterNumber(
114115
self.INPUT_DECIMATION,
115-
"DECIMATION",
116+
"DECIMATION (Point Geometry Data)",
116117
QgsProcessingParameterNumber.Integer,
117118
defaultValue=1,
118119
optional=True,
@@ -122,7 +123,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
122123
self.addParameter(
123124
QgsProcessingParameterNumber(
124125
self.INPUT_SPACING,
125-
"SPACING",
126+
"SPACING (Line Geometry Data)",
126127
QgsProcessingParameterNumber.Double,
127128
defaultValue=200.0,
128129
optional=True,
@@ -176,19 +177,11 @@ def processAlgorithm(
176177
samples = sampler.sample(spatial_data_gdf)
177178

178179
fields = QgsFields()
179-
if samples is not None and not samples.empty:
180-
for column_name in samples.columns:
181-
dtype = samples[column_name].dtype
182-
dtype_str = str(dtype)
183-
184-
if dtype_str in ['float16', 'float32', 'float64']:
185-
field_type = QVariant.Double
186-
elif dtype_str in ['int8', 'int16', 'int32', 'int64']:
187-
field_type = QVariant.Int
188-
else:
189-
field_type = QVariant.String
190-
191-
fields.append(QgsField(column_name, field_type))
180+
fields.append(QgsField("ID", QVariant.String))
181+
fields.append(QgsField("X", QVariant.Double))
182+
fields.append(QgsField("Y", QVariant.Double))
183+
fields.append(QgsField("Z", QVariant.Double))
184+
fields.append(QgsField("featureId", QVariant.String))
192185

193186
crs = None
194187
if spatial_data_gdf is not None and spatial_data_gdf.crs is not None:
@@ -215,21 +208,13 @@ def processAlgorithm(
215208
#spacing has no z values
216209
feature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(row['X'], row['Y'])))
217210

218-
attributes = []
219-
for column_name in samples.columns:
220-
value = row.get(column_name)
221-
dtype = samples[column_name].dtype
222-
223-
if pd.isna(value):
224-
attributes.append(None)
225-
elif dtype in ['float16', 'float32', 'float64']:
226-
attributes.append(float(value))
227-
elif dtype in ['int8', 'int16', 'int32', 'int64']:
228-
attributes.append(int(value))
229-
else:
230-
attributes.append(str(value))
231-
232-
feature.setAttributes(attributes)
211+
feature.setAttributes([
212+
str(row.get('ID', '')),
213+
float(row.get('X', 0)),
214+
float(row.get('Y', 0)),
215+
float(row.get('Z', 0)) if pd.notna(row.get('Z')) else 0.0,
216+
str(row.get('featureId', ''))
217+
])
233218

234219
sink.addFeature(feature)
235220

0 commit comments

Comments
 (0)