Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions map2loop/main/vectorLayerWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
QgsWkbTypes,
QgsCoordinateReferenceSystem,
QgsFeatureSink,
QgsProcessingException
QgsProcessingException,
QgsPoint,
QgsPointXY,
)

from qgis.PyQt.QtCore import QVariant, QDateTime
Expand Down Expand Up @@ -392,7 +394,7 @@ def dataframeToQgsLayer(
attr_columns = [f.name() for f in fields]

# Iterate rows and write features
for i, (idx, row) in enumerate(df.iterrows(), start=1):
for i, (_idx, row) in enumerate(df.iterrows(), start=1):
if feedback.isCanceled():
break

Expand Down
46 changes: 34 additions & 12 deletions map2loop/processing/algorithms/extract_basal_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
QgsProcessingFeedback,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterField
)
# Internal imports
from ...main.vectorLayerWrapper import qgsLayerToGeoDataFrame, GeoDataFrameToQgsLayer
from map2loop import ContactExtractor
from ...main.vectorLayerWrapper import qgsLayerToGeoDataFrame, GeoDataFrameToQgsLayer
from map2loop.contact_extractor import ContactExtractor


class BasalContactsAlgorithm(QgsProcessingAlgorithm):
Expand Down Expand Up @@ -63,6 +65,16 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
[QgsProcessing.TypeVectorPolygon],
)
)
self.addParameter(
QgsProcessingParameterField(
'UNIT_NAME_FIELD',
'Unit Name Field',
parentLayerParameterName=self.INPUT_GEOLOGY,
type=QgsProcessingParameterField.String,
defaultValue='unitname'
)
)

self.addParameter(
QgsProcessingParameterFeatureSource(
self.INPUT_FAULTS,
Expand All @@ -71,12 +83,13 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
optional=True,
)
)

self.addParameter(
QgsProcessingParameterFeatureSource(
QgsProcessingParameterString(
self.INPUT_STRATI_COLUMN,
"STRATIGRAPHIC_COLUMN",
[QgsProcessing.TypeVectorLine],
"Stratigraphic Column Names",
defaultValue="",
optional=True
)
)

Expand All @@ -94,22 +107,31 @@ def processAlgorithm(
feedback: QgsProcessingFeedback,
) -> dict[str, Any]:

geology = self.parameterAsSource(parameters, self.INPUT_GEOLOGY, context)
faults = self.parameterAsSource(parameters, self.INPUT_FAULTS, context)
strati_column = self.parameterAsSource(parameters, self.INPUT_STRATI_COLUMN, context)
geology = self.parameterAsVectorLayer(parameters, self.INPUT_GEOLOGY, context)
faults = self.parameterAsVectorLayer(parameters, self.INPUT_FAULTS, context)
strati_column = self.parameterAsString(parameters, self.INPUT_STRATI_COLUMN, context)

if strati_column and strati_column.strip():
strati_column = [unit.strip() for unit in strati_column.split(',')]

unit_name_field = self.parameterAsString(parameters, 'UNIT_NAME_FIELD', context)

geology = qgsLayerToGeoDataFrame(geology)
faults = qgsLayerToGeoDataFrame(faults) if faults else None

if unit_name_field != 'UNITNAME' and unit_name_field in geology.columns:
geology = geology.rename(columns={unit_name_field: 'UNITNAME'})

feedback.pushInfo("Extracting Basal Contacts...")
contact_extractor = ContactExtractor(geology, faults, feedback)
contact_extractor.extract_basal_contacts(strati_column)

contact_extractor = ContactExtractor(geology, faults)
basal_contacts = contact_extractor.extract_basal_contacts(strati_column)
basal_contacts = GeoDataFrameToQgsLayer(
self,
contact_extractor.basal_contacts,
parameters=parameters,
context=context,
output_key=self.OUTPUT,
feedback=feedback,
)
return {self.OUTPUT: basal_contacts}
Expand Down