Skip to content

Commit

Permalink
Merge pull request #815 from dsgoficial/dev
Browse files Browse the repository at this point in the history
Versão 4.16.0
  • Loading branch information
phborba authored Nov 27, 2024
2 parents 67c7bca + 1c1eae1 commit cfa546d
Show file tree
Hide file tree
Showing 41 changed files with 184,065 additions and 174,404 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# CHANGELOG

## 4.16.0 - 2024-11-27

Novas Funcionalidades:

- Nova ferramenta para fechar linhas;
- Criação do algoritmo de generalização de edificações (ponto);
- Criação do algoritmo de generalização de edificações (polígono);
- Criação do algoritmo de generalização de pistas de pouso;
- Criação do algoritmo de generalização de massas d'água (polígono), ilhas (polígono), trechos de drenagem (linha) e barragens (linha);

Melhorias:

- O processo de criação de moldura agora aceita múltiplos MIs ou INOMs separados por vírgula;
- As subdivisões das molduras foram padronizadas por escala, para garantir a existência de vértices das molduras desde a escala 1:25.000 até a escala 1:205.000;

Correção de bugs:

- Correção de bug no action do processo de inventário (os actions de vetor e raster agora foram unidos em um só);
- Corrige nodata no processo de extrair pontos cotados;
- Corrige rotina de construir o grid para edição;
- Corrige bug no processo de identificar feições fechadas menores que a tolerância (Find Small Closed Lines Algorithm);
- Corrige bug no processo de remover geometrias nulas;

## 4.14.0 - 2024-06-20

Novas Funcionalidades:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def processAlgorithm(self, parameters, context, feedback):
"""
Here is where the processing itself takes place.
"""
inputLyr = self.parameterAsVectorLayer(parameters, self.INPUT, context)
gridLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
attribute = self.parameterAsFields(parameters, self.ATTRIBUTE_INDEX, context)[0]
id_attribute = self.parameterAsFields(parameters, self.ATTRIBUTE_ID, context)[0]
id_value = self.parameterAsInt(parameters, self.ID_VALUE, context)
Expand All @@ -233,23 +233,41 @@ def processAlgorithm(self, parameters, context, feedback):
font = self.parameterAsFont(parameters, self.FONT, context)
fontLL = self.parameterAsFont(parameters, self.FONT_LL, context)
llcolor = self.parameterAsColor(parameters, self.COLOR_LL, context)
GridAndLabelCreator().geo_test(
inputLyr,
attribute,
id_attribute,
id_value,
spacing,
crossX,
crossY,
scale,
color,
fontSize,
font,
fontLL,
llcolor,

gridGenerator = GridAndLabelCreator()
gridCrs = gridLayer.crs().authid()
srid = gridCrs.replace("EPSG:", "")
gridGeometry = next(gridLayer.getFeatures()).geometry()
gridOpts = {
"crossX": crossX,
"crossY": crossY,
"fontSize": fontSize,
"font": font,
"fontLL": fontLL,
"llcolor": llcolor,
"linwidth_geo": 0.07,
"linwidth_utm": 0.05,
"linwidth_buffer_geo": 0,
"linwidth_buffer_utm": 0,
"geo_grid_color": llcolor,
"utm_grid_color": color,
"geo_grid_buffer_color": llcolor,
"utm_grid_buffer_color": color,
"masks_check": True,
}
gridGenerator.styleCreator(
feature_geometry=gridGeometry,
layer_bound=gridLayer,
utmSRID=srid,
id_attr="id",
id_value=1,
scale=scale,
spacing=spacing,
**gridOpts,
)
gridLayer.triggerRepaint()

return {self.OUTPUT: inputLyr}
return {self.OUTPUT: gridLayer}

def name(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@
from qgis.core import (
Qgis,
QgsProcessing,
QgsProcessingException,
QgsProcessingMultiStepFeedback,
QgsProcessingParameterEnum,
QgsProcessingParameterFeatureSource,
QgsFeedback,
QgsProcessingContext,
QgsFeature,
QgsVectorLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterBoolean,
QgsProcessingParameterDistance,
)

from ...algRunner import AlgRunner
Expand All @@ -66,11 +63,11 @@ def initAlgorithm(self, config):
)
)
self.addParameter(
QgsProcessingParameterNumber(
QgsProcessingParameterDistance(
self.MIN_LENGTH,
self.tr("Minimum size"),
minValue=0,
type=QgsProcessingParameterNumber.Double,
parentParameterName=self.INPUT,
defaultValue=0.001,
)
)
Expand Down Expand Up @@ -98,26 +95,18 @@ def processAlgorithm(self, parameters, context, feedback):
"""
Here is where the processing itself takes place.
"""
try:
import networkx as nx
except ImportError:
raise QgsProcessingException(
self.tr(
"This algorithm requires the Python networkx library. Please install this library and try again."
)
)
# get the network handler
self.algRunner = AlgRunner()
self.layerHandler = LayerHandler()
inputLayer = self.parameterAsLayer(parameters, self.INPUT, context)
minLen = self.parameterAsDouble(parameters, self.MIN_LENGTH, context)
method = self.parameterAsEnum(parameters, self.METHOD, context)

nSteps = 9
nSteps = 6
multiStepFeedback = QgsProcessingMultiStepFeedback(nSteps, feedback)
currentStep = 0
multiStepFeedback.setCurrentStep(currentStep)
multiStepFeedback.setProgressText(self.tr("Building aux structures"))
multiStepFeedback.setProgressText(self.tr("Creating local cache..."))
localCache = self.algRunner.runCreateFieldWithExpression(
inputLyr=parameters[self.INPUT],
expression="$id",
Expand All @@ -128,84 +117,82 @@ def processAlgorithm(self, parameters, context, feedback):
)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
orientedLines = self.algRunner.runSetLineOrientation(
inputLayer=localCache,
context=context,
feedback=multiStepFeedback,
multiStepFeedback.setProgressText(
self.tr("Filtering small individual lines...")
)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
self.algRunner.runCreateSpatialIndex(
inputLyr=orientedLines,
smallIndividualLines = self.algRunner.runFilterExpression(
localCache,
expression=f"length($geometry)<{minLen}",
context=context,
feedback=multiStepFeedback,
is_child_algorithm=True,
)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
nodesLayer = self.algRunner.runExtractSpecificVertices(
inputLyr=orientedLines,
vertices="0,-1",
multiStepFeedback.setProgressText(self.tr("Dissolving small lines..."))
dissolved = self.algRunner.runDissolve(
inputLyr=smallIndividualLines,
context=context,
feedback=multiStepFeedback,
# is_child_algorithm=True,
)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
nodesLayer = self.algRunner.runCreateFieldWithExpression(
inputLyr=nodesLayer,
expression="$id",
fieldName="nfeatid",
fieldType=1,
multiStepFeedback.setProgressText(self.tr("Filtering small dissolved lines..."))
smallLines = self.algRunner.runFilterExpression(
dissolved,
expression=f"length($geometry)<{minLen}",
context=context,
feedback=multiStepFeedback,
)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
self.algRunner.runCreateSpatialIndex(
inputLyr=nodesLayer,
context=context,
feedback=multiStepFeedback,
is_child_algorithm=True,
)

currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
(
nodeDict,
nodeIdDict,
edgeDict,
hashDict,
networkDirectedGraph,
nodeLayerIdDict,
) = graphHandler.buildAuxStructures(
nx,
nodesLayer=nodesLayer,
edgesLayer=orientedLines,
feedback=multiStepFeedback,
useWkt=False,
computeNodeLayerIdDict=True,
addEdgeLength=True,
graphType=graphHandler.GraphType.MULTIDIGRAPH,
)
multiStepFeedback.setProgressText(self.tr("Filtering closed lines..."))
closedLines = self.findClosedLines(smallLines)
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
idsToRemove = graphHandler.find_small_closed_line_groups(
nx, networkDirectedGraph, minLength=minLen, feedback=multiStepFeedback
)

multiStepFeedback.setProgressText(self.tr("Finding lines..."))
lines = self.withinFeatures(localCache, closedLines)
idsToRemove = {line["featid"] for line in lines}
currentStep += 1
multiStepFeedback.setCurrentStep(currentStep)
self.manageSelectedIdsUsingInputMethod(inputLayer, method, idsToRemove)
return {}

def manageSelectedIdsUsingInputMethod(self, networkLayer, method, idsToRemove):
def findClosedLines(self, inputLyr) -> Set[QgsFeature]:
closedLines = set()
for feat in inputLyr.getFeatures():
geom = feat.geometry()
if geom.isMultipart():
for part in geom.asMultiPolyline():
if part[0] == part[-1]:
closedLines.add(feat)
else:
line = geom.asPolyline()
if line[0] == line[-1]:
closedLines.add(feat)
return closedLines

def withinFeatures(self, inputLyr, features) -> Set[QgsFeature]:
featsWithin = set()
for feature in features:
geometry = feature.geometry()
bbox = geometry.boundingBox()
for feat in inputLyr.getFeatures(bbox):
geom = feat.geometry()
if geom.within(geometry):
featsWithin.add(feat)
return featsWithin

def manageSelectedIdsUsingInputMethod(
self, inputLyr: QgsVectorLayer, method, idsToRemove
):
if method != 0:
networkLayer.selectByIds(list(idsToRemove), self.selectionIdDict[method])
inputLyr.selectByIds(list(idsToRemove), self.selectionIdDict[method])
return {}
networkLayer.startEditing()
networkLayer.beginEditCommand(self.tr("Deleting features"))
networkLayer.deleteFeatures(list(idsToRemove))
networkLayer.endEditCommand()
inputLyr.startEditing()
inputLyr.beginEditCommand(self.tr("Deleting features"))
inputLyr.deleteFeatures(list(idsToRemove))
inputLyr.endEditCommand()
return {}

def name(self):
Expand Down
Loading

0 comments on commit cfa546d

Please sign in to comment.