Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple indexes on CreateFrameAlgorithm #811

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def initAlgorithm(self, config):
defaultValue=0,
)
)
self.addParameter(QgsProcessingParameterString(self.INDEX, self.tr("Index")))
self.addParameter(
QgsProcessingParameterString(
self.INDEX,
self.tr("Index (comma-separated for multiple)")
)
)
self.addParameter(QgsProcessingParameterCrs(self.CRS, self.tr("CRS")))
self.addParameter(
QgsProcessingParameterNumber(
Expand Down Expand Up @@ -133,24 +138,32 @@ def processAlgorithm(self, parameters, context, feedback):
)
)
indexTypeIdx = self.parameterAsEnum(parameters, self.INDEX_TYPE, context)
inputIndex = self.parameterAsString(parameters, self.INDEX, context)
if startScaleIdx in [0, 1] and indexTypeIdx == 0:
raise QgsProcessingException(
self.tr("{index} is only valid for scales 250k and below.").format(
index=self.indexTypes[indexTypeIdx]
)
)
if inputIndex is None or inputIndex == "":
inputIndexString = self.parameterAsString(parameters, self.INDEX, context)

if inputIndexString is None or inputIndexString.strip() == "":
raise QgsProcessingException(
self.tr("Invalid {index}").format(index=self.indexTypes[indexTypeIdx])
)
index = self.getIndex(inputIndex, indexTypeIdx, startScaleIdx)
if index is None or not self.validateIndex(index):

inputIndexes = [idx.strip() for idx in inputIndexString.split(",")]

if startScaleIdx in [0, 1] and indexTypeIdx == 0:
raise QgsProcessingException(
self.tr("Invalid {index} format.").format(
self.tr("{index} is only valid for scales 250k and below.").format(
index=self.indexTypes[indexTypeIdx]
)
)

for inputIndex in inputIndexes:
index = self.getIndex(inputIndex, indexTypeIdx, startScaleIdx)
if index is None or not self.validateIndex(index):
raise QgsProcessingException(
self.tr("Invalid {index} format: {value}").format(
index=self.indexTypes[indexTypeIdx],
value=inputIndex
)
)

crs = self.parameterAsCrs(parameters, self.CRS, context)
if crs is None or not crs.isValid():
raise QgsProcessingException(self.tr("Invalid CRS."))
Expand All @@ -162,23 +175,37 @@ def processAlgorithm(self, parameters, context, feedback):
(output_sink, output_sink_id) = self.parameterAsSink(
parameters, self.OUTPUT, context, fields, QgsWkbTypes.Polygon, crs
)

featureList = []
coordinateTransformer = QgsCoordinateTransform(
QgsCoordinateReferenceSystem(crs.geographicCrsAuthId()),
crs,
QgsProject.instance(),
)
featureHandler.getSystematicGridFeatures(
featureList,
index,
stopScale,
coordinateTransformer,
fields,
xSubdivisions=xSubdivisions,
ySubdivisions=ySubdivisions,
feedback=feedback,
)

total = len(inputIndexes)
for i, inputIndex in enumerate(inputIndexes):
if feedback.isCanceled():
break

index = self.getIndex(inputIndex, indexTypeIdx, startScaleIdx)
feedback.setProgress(int((i / total) * 100))
feedback.pushInfo(f"Processing index {i+1}/{total}: {inputIndex}")

featureHandler.getSystematicGridFeatures(
featureList,
index,
stopScale,
coordinateTransformer,
fields,
xSubdivisions=xSubdivisions,
ySubdivisions=ySubdivisions,
feedback=feedback,
)

for feat in featureList:
if feedback.isCanceled():
break
output_sink.addFeature(feat, QgsFeatureSink.FastInsert)

return {"OUTPUT": output_sink_id}
Expand Down
Loading