2222 QgsProcessingFeedback ,
2323 QgsProcessingParameterFeatureSink ,
2424 QgsProcessingParameterFeatureSource ,
25+ QgsProcessingParameterEnum ,
26+ QgsProcessingParameterNumber ,
27+ QgsProcessingParameterField ,
28+ QgsProcessingParameterMatrix
2529)
2630# Internal imports
27- from ...main .vectorLayerWrapper import qgsLayerToGeoDataFrame , GeoDataFrameToQgsLayer
31+ from ...main .vectorLayerWrapper import qgsLayerToGeoDataFrame , GeoDataFrameToQgsLayer , qgsLayerToDataFrame , dataframeToQgsLayer
2832from map2loop .map2loop .thickness_calculator import InterpolatedStructure , StructuralPoint
2933
3034
@@ -62,129 +66,52 @@ def groupId(self) -> str:
6266
6367 def initAlgorithm (self , config : Optional [dict [str , Any ]] = None ) -> None :
6468 """Initialize the algorithm parameters."""
65-
66-
6769
6870 self .addParameter (
69- QgsProcessingParameterFeatureSource (
71+ QgsProcessingParameterEnum (
7072 self .INPUT_THICKNESS_CALCULATOR_TYPE ,
7173 "Thickness Calculator Type" ,
72- [QgsProcessing .TypeVectorPoint ],
74+ options = ['InterpolatedStructure' ,'StructuralPoint' ],
75+ allowMultiple = False ,
7376 )
7477 )
75-
76- self .addParameter (
77- QgsProcessingParameterFeatureSource (
78- self .INPUT_BASAL_CONTACTS ,
79- "Basal Contacts" ,
80- [QgsProcessing .TypeVectorPoint ],
81- )
82- )
83-
8478 self .addParameter (
8579 QgsProcessingParameterFeatureSource (
8680 self .INPUT_DTM ,
8781 "DTM" ,
8882 [QgsProcessing .TypeVectorRaster ],
8983 )
9084 )
91-
9285 self .addParameter (
93- QgsProcessingParameterFeatureSource (
94- self .INPUT_GEOLOGY ,
95- "GEOLOGY" ,
96- [QgsProcessing .TypeVectorPolygon ],
86+ QgsProcessingParameterEnum (
87+ self .INPUT_BOUNDING_BOX ,
88+ "Bounding Box" ,
89+ options = ['minx' ,'miny' ,'maxx' ,'maxy' ],
90+ allowMultiple = True ,
9791 )
9892 )
93+ self .addParameter (
94+ QgsProcessingParameterNumber (
95+ self .INPUT_MAX_LINE_LENGTH ,
96+ "Max Line Length" ,
97+ minValue = 0 ,
98+ defaultValue = 1000
99+ )
100+ )
99101 self .addParameter (
100102 QgsProcessingParameterFeatureSource (
101- self .INPUT_FAULTS ,
102- "FAULTS " ,
103+ self .INPUT_UNITS ,
104+ "Units " ,
103105 [QgsProcessing .TypeVectorLine ],
104- optional = True ,
105106 )
106107 )
107-
108108 self .addParameter (
109109 QgsProcessingParameterFeatureSource (
110- self .INPUT_STRATI_COLUMN ,
111- "STRATIGRAPHIC_COLUMN " ,
110+ self .INPUT_BASAL_CONTACTS ,
111+ "Basal Contacts " ,
112112 [QgsProcessing .TypeVectorLine ],
113113 )
114114 )
115-
116- self .addParameter (
117- QgsProcessingParameterFeatureSink (
118- self .OUTPUT ,
119- "Thickness" ,
120- )
121- )
122-
123- def processAlgorithm (
124- self ,
125- parameters : dict [str , Any ],
126- context : QgsProcessingContext ,
127- feedback : QgsProcessingFeedback ,
128- ) -> dict [str , Any ]:
129-
130- geology = self .parameterAsSource (parameters , self .INPUT_GEOLOGY , context )
131- faults = self .parameterAsSource (parameters , self .INPUT_FAULTS , context )
132- strati_column = self .parameterAsSource (parameters , self .INPUT_STRATI_COLUMN , context )
133-
134- geology = qgsLayerToGeoDataFrame (geology )
135- faults = qgsLayerToGeoDataFrame (faults ) if faults else None
136-
137- feedback .pushInfo ("Extracting Basal Contacts..." )
138- contact_extractor = ContactExtractor (geology , faults , feedback )
139- contact_extractor .extract_basal_contacts (strati_column )
140-
141- basal_contacts = GeoDataFrameToQgsLayer (
142- self ,
143- contact_extractor .basal_contacts ,
144- parameters = parameters ,
145- context = context ,
146- feedback = feedback ,
147- )
148- return {self .OUTPUT : basal_contacts }
149-
150- def createInstance (self ) -> QgsProcessingAlgorithm :
151- """Create a new instance of the algorithm."""
152- return self .__class__ () # BasalContactsAlgorithm()
153-
154-
155-
156- class InterpolatedStructureAlgorithm (QgsProcessingAlgorithm ):
157- """Processing algorithm for thickness calculations."""
158-
159-
160- INPUT_UNITS = 'UNITS'
161- INPUT_STRATI_COLUMN = 'STRATIGRAPHIC_COLUMN'
162- INPUT_BASAL_CONTACTS = 'BASAL_CONTACTS'
163- INPUT_STRUCTURE_DATA = 'STRUCTURE_DATA'
164- INPUT_GEOLOGY = 'GEOLOGY'
165- INPUT_SAMPLED_CONTACTS = 'SAMPLED_CONTACTS'
166-
167- OUTPUT = "THICKNESS"
168-
169- def name (self ) -> str :
170- """Return the algorithm name."""
171- return "thickness_calculator"
172-
173- def displayName (self ) -> str :
174- """Return the algorithm display name."""
175- return "Loop3d: Thickness Calculator"
176-
177- def group (self ) -> str :
178- """Return the algorithm group name."""
179- return "Loop3d"
180-
181- def groupId (self ) -> str :
182- """Return the algorithm group ID."""
183- return "loop3d"
184-
185- def initAlgorithm (self , config : Optional [dict [str , Any ]] = None ) -> None :
186- """Initialize the algorithm parameters."""
187-
188115 self .addParameter (
189116 QgsProcessingParameterFeatureSource (
190117 self .INPUT_GEOLOGY ,
@@ -193,122 +120,32 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
193120 )
194121 )
195122 self .addParameter (
196- QgsProcessingParameterFeatureSource (
197- self .INPUT_FAULTS ,
198- "FAULTS" ,
199- [QgsProcessing .TypeVectorLine ],
200- optional = True ,
201- )
202- )
203-
204- self .addParameter (
205- QgsProcessingParameterFeatureSource (
206- self .INPUT_STRATI_COLUMN ,
207- "STRATIGRAPHIC_COLUMN" ,
208- [QgsProcessing .TypeVectorLine ],
209- )
210- )
211-
212- self .addParameter (
213- QgsProcessingParameterFeatureSink (
214- self .OUTPUT ,
215- "Basal Contacts" ,
216- )
217- )
218-
219- def processAlgorithm (
220- self ,
221- parameters : dict [str , Any ],
222- context : QgsProcessingContext ,
223- feedback : QgsProcessingFeedback ,
224- ) -> dict [str , Any ]:
225-
226- geology = self .parameterAsSource (parameters , self .INPUT_GEOLOGY , context )
227- faults = self .parameterAsSource (parameters , self .INPUT_FAULTS , context )
228- strati_column = self .parameterAsSource (parameters , self .INPUT_STRATI_COLUMN , context )
229-
230- geology = qgsLayerToGeoDataFrame (geology )
231- faults = qgsLayerToGeoDataFrame (faults ) if faults else None
232-
233- feedback .pushInfo ("Extracting Basal Contacts..." )
234- contact_extractor = ContactExtractor (geology , faults , feedback )
235- contact_extractor .extract_basal_contacts (strati_column )
236-
237- basal_contacts = GeoDataFrameToQgsLayer (
238- self ,
239- contact_extractor .basal_contacts ,
240- parameters = parameters ,
241- context = context ,
242- feedback = feedback ,
243- )
244- return {self .OUTPUT : basal_contacts }
245-
246- def createInstance (self ) -> QgsProcessingAlgorithm :
247- """Create a new instance of the algorithm."""
248- return self .__class__ () # BasalContactsAlgorithm()
249-
250-
251-
252- class StructuralPointAlgorithm (QgsProcessingAlgorithm ):
253- """Processing algorithm for thickness calculations."""
254-
255-
256- INPUT_UNITS = 'UNITS'
257- INPUT_STRATI_COLUMN = 'STRATIGRAPHIC_COLUMN'
258- INPUT_BASAL_CONTACTS = 'BASAL_CONTACTS'
259- INPUT_STRUCTURE_DATA = 'STRUCTURE_DATA'
260- INPUT_GEOLOGY = 'GEOLOGY'
261- INPUT_SAMPLED_CONTACTS = 'SAMPLED_CONTACTS'
262-
263- OUTPUT = "THICKNESS"
264-
265- def name (self ) -> str :
266- """Return the algorithm name."""
267- return "thickness_calculator"
268-
269- def displayName (self ) -> str :
270- """Return the algorithm display name."""
271- return "Loop3d: Thickness Calculator"
272-
273- def group (self ) -> str :
274- """Return the algorithm group name."""
275- return "Loop3d"
276-
277- def groupId (self ) -> str :
278- """Return the algorithm group ID."""
279- return "loop3d"
280-
281- def initAlgorithm (self , config : Optional [dict [str , Any ]] = None ) -> None :
282- """Initialize the algorithm parameters."""
283-
284- self .addParameter (
285- QgsProcessingParameterFeatureSource (
286- self .INPUT_GEOLOGY ,
287- "GEOLOGY" ,
288- [QgsProcessing .TypeVectorPolygon ],
123+ QgsProcessingParameterMatrix (
124+ name = self .INPUT_STRATI_COLUMN ,
125+ description = "Stratigraphic Order" ,
126+ headers = ["Unit" ],
127+ numberRows = 0 ,
128+ defaultValue = []
289129 )
290130 )
291131 self .addParameter (
292132 QgsProcessingParameterFeatureSource (
293- self .INPUT_FAULTS ,
294- "FAULTS" ,
295- [QgsProcessing .TypeVectorLine ],
296- optional = True ,
133+ self .INPUT_SAMPLED_CONTACTS ,
134+ "SAMPLED_CONTACTS" ,
135+ [QgsProcessing .TypeVectorPoint ],
297136 )
298137 )
299-
300138 self .addParameter (
301139 QgsProcessingParameterFeatureSource (
302- self .INPUT_STRATI_COLUMN ,
303- "STRATIGRAPHIC_COLUMN " ,
304- [QgsProcessing .TypeVectorLine ],
140+ self .INPUT_STRUCTURE_DATA ,
141+ "STRUCTURE_DATA " ,
142+ [QgsProcessing .TypeVectorPoint ],
305143 )
306144 )
307-
308145 self .addParameter (
309146 QgsProcessingParameterFeatureSink (
310147 self .OUTPUT ,
311- "Basal Contacts " ,
148+ "Thickness " ,
312149 )
313150 )
314151
@@ -319,25 +156,66 @@ def processAlgorithm(
319156 feedback : QgsProcessingFeedback ,
320157 ) -> dict [str , Any ]:
321158
322- geology = self .parameterAsSource (parameters , self .INPUT_GEOLOGY , context )
323- faults = self .parameterAsSource (parameters , self .INPUT_FAULTS , context )
324- strati_column = self .parameterAsSource (parameters , self .INPUT_STRATI_COLUMN , context )
325-
326- geology = qgsLayerToGeoDataFrame (geology )
327- faults = qgsLayerToGeoDataFrame (faults ) if faults else None
328-
329- feedback .pushInfo ("Extracting Basal Contacts..." )
330- contact_extractor = ContactExtractor (geology , faults , feedback )
331- contact_extractor .extract_basal_contacts (strati_column )
332-
333- basal_contacts = GeoDataFrameToQgsLayer (
159+ feedback .pushInfo ("Initialising Thickness Calculation Algorithm..." )
160+ thickness_type = self .parameterAsEnum (parameters , self .INPUT_THICKNESS_CALCULATOR_TYPE , context )
161+ dtm_data = self .parameterAsSource (parameters , self .INPUT_DTM , context )
162+ bounding_box = self .parameterAsEnum (parameters , self .INPUT_BOUNDING_BOX , context )
163+ max_line_length = self .parameterAsNumber (parameters , self .INPUT_MAX_LINE_LENGTH , context )
164+ units = self .parameterAsSource (parameters , self .INPUT_UNITS , context )
165+ basal_contacts = self .parameterAsSource (parameters , self .INPUT_BASAL_CONTACTS , context )
166+ geology_data = self .parameterAsSource (parameters , self .INPUT_GEOLOGY , context )
167+ stratigraphic_order = self .parameterAsMatrix (parameters , self .INPUT_STRATI_COLUMN , context )
168+ structure_data = self .parameterAsSource (parameters , self .INPUT_STRUCTURE_DATA , context )
169+ sampled_contacts = self .parameterAsSource (parameters , self .INPUT_SAMPLED_CONTACTS , context )
170+
171+ # convert layers to dataframe or geodataframe
172+ geology_data = qgsLayerToGeoDataFrame (geology_data )
173+ units = qgsLayerToDataFrame (units )
174+ basal_contacts = qgsLayerToGeoDataFrame (basal_contacts )
175+ structure_data = qgsLayerToDataFrame (structure_data )
176+ sampled_contacts = qgsLayerToDataFrame (sampled_contacts )
177+
178+ feedback .pushInfo ("Calculating unit thicknesses..." )
179+
180+ if thickness_type == "InterpolatedStructure" :
181+ thickness_calculator = InterpolatedStructure (
182+ dtm_data = dtm_data ,
183+ bounding_box = bounding_box ,
184+ )
185+ thickness_calculator .compute (
186+ units ,
187+ stratigraphic_order ,
188+ basal_contacts ,
189+ structure_data ,
190+ geology_data ,
191+ sampled_contacts
192+ )
193+
194+ if thickness_type == "StructuralPoint" :
195+ thickness_calculator = StructuralPoint (
196+ dtm_data = dtm_data ,
197+ bounding_box = bounding_box ,
198+ max_line_length = max_line_length ,
199+ )
200+ thickness_calculator .compute (
201+ units ,
202+ stratigraphic_order ,
203+ basal_contacts ,
204+ structure_data ,
205+ geology_data ,
206+ sampled_contacts
207+ )
208+
209+ #TODO: convert thicknesses dataframe to qgs layer
210+ thicknesses = dataframeToQgsLayer (
334211 self ,
335- contact_extractor .basal_contacts ,
212+ # contact_extractor.basal_contacts,
336213 parameters = parameters ,
337214 context = context ,
338215 feedback = feedback ,
339216 )
340- return {self .OUTPUT : basal_contacts }
217+
218+ return {self .OUTPUT : thicknesses [1 ]}
341219
342220 def createInstance (self ) -> QgsProcessingAlgorithm :
343221 """Create a new instance of the algorithm."""
0 commit comments