1010"""
1111# Python imports
1212from typing import Any , Optional
13- from qgis .PyQt .QtCore import QVariant
13+ from qgis .PyQt .QtCore import QMetaType , QVariant
1414from osgeo import gdal
1515import pandas as pd
1616
1717# QGIS imports
1818from qgis .core import (
19+ QgsFeatureSink ,
1920 QgsProcessing ,
2021 QgsProcessingAlgorithm ,
2122 QgsProcessingContext ,
3132 QgsFeature ,
3233 QgsGeometry ,
3334 QgsPointXY ,
35+ QgsVectorLayer ,
3436 QgsWkbTypes ,
3537 QgsCoordinateReferenceSystem
3638)
@@ -75,7 +77,8 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
7577 QgsProcessingParameterEnum (
7678 self .INPUT_SAMPLER_TYPE ,
7779 "SAMPLER_TYPE" ,
78- ["Decimator" , "Spacing" ],
80+ ["Decimator (Point Geometry Data)" ,
81+ "Spacing (Line Geometry Data)" ],
7982 defaultValue = 0
8083 )
8184 )
@@ -110,7 +113,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
110113 self .addParameter (
111114 QgsProcessingParameterNumber (
112115 self .INPUT_DECIMATION ,
113- "DECIMATION" ,
116+ "DECIMATION (Point Geometry Data) " ,
114117 QgsProcessingParameterNumber .Integer ,
115118 defaultValue = 1 ,
116119 optional = True ,
@@ -120,7 +123,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
120123 self .addParameter (
121124 QgsProcessingParameterNumber (
122125 self .INPUT_SPACING ,
123- "SPACING" ,
126+ "SPACING (Line Geometry Data) " ,
124127 QgsProcessingParameterNumber .Double ,
125128 defaultValue = 200.0 ,
126129 optional = True ,
@@ -174,19 +177,11 @@ def processAlgorithm(
174177 samples = sampler .sample (spatial_data_gdf )
175178
176179 fields = QgsFields ()
177- if samples is not None and not samples .empty :
178- for column_name in samples .columns :
179- dtype = samples [column_name ].dtype
180- dtype_str = str (dtype )
181-
182- if dtype_str in ['float16' , 'float32' , 'float64' ]:
183- field_type = QVariant .Double
184- elif dtype_str in ['int8' , 'int16' , 'int32' , 'int64' ]:
185- field_type = QVariant .Int
186- else :
187- field_type = QVariant .String
188-
189- 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 ))
190185
191186 crs = None
192187 if spatial_data_gdf is not None and spatial_data_gdf .crs is not None :
@@ -213,21 +208,13 @@ def processAlgorithm(
213208 #spacing has no z values
214209 feature .setGeometry (QgsGeometry .fromPointXY (QgsPointXY (row ['X' ], row ['Y' ])))
215210
216- attributes = []
217- for column_name in samples .columns :
218- value = row .get (column_name )
219- dtype = samples [column_name ].dtype
220-
221- if pd .isna (value ):
222- attributes .append (None )
223- elif dtype in ['float16' , 'float32' , 'float64' ]:
224- attributes .append (float (value ))
225- elif dtype in ['int8' , 'int16' , 'int32' , 'int64' ]:
226- attributes .append (int (value ))
227- else :
228- attributes .append (str (value ))
229-
230- 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+ ])
231218
232219 sink .addFeature (feature )
233220
0 commit comments