Skip to content
Snippets Groups Projects
Commit ccab8d44 authored by Arnaud MORVAN's avatar Arnaud MORVAN
Browse files

Add tests on repair profiles

parent fe151d29
No related branches found
No related tags found
1 merge request!75Gsedfqgis 118 create dedicated algo
from qgis.core import ( from qgis.core import (
QgsProcessing, QgsProcessing,
QgsProcessingParameterVectorLayer, QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink, QgsProcessingParameterFeatureSink,
QgsProcessingOutputLayerDefinition, QgsProcessingOutputLayerDefinition,
) )
...@@ -15,7 +15,7 @@ class RepairProfilesAlgorithm(PreCourlisAlgorithm): ...@@ -15,7 +15,7 @@ class RepairProfilesAlgorithm(PreCourlisAlgorithm):
def initAlgorithm(self, config=None): def initAlgorithm(self, config=None):
self.addParameter( self.addParameter(
QgsProcessingParameterVectorLayer( QgsProcessingParameterFeatureSource(
self.INPUT, self.INPUT,
self.tr("Input"), self.tr("Input"),
types=[QgsProcessing.TypeVectorLine], types=[QgsProcessing.TypeVectorLine],
...@@ -33,97 +33,102 @@ class RepairProfilesAlgorithm(PreCourlisAlgorithm): ...@@ -33,97 +33,102 @@ class RepairProfilesAlgorithm(PreCourlisAlgorithm):
) )
) )
def processAlgorithm(self, parameters, context, model_feedback): def processAlgorithm(self, parameters, context, feedback):
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
output = QgsProcessingOutputLayerDefinition(parameters[self.OUTPUT]) output = QgsProcessingOutputLayerDefinition(parameters[self.OUTPUT])
output.destinationName = self.tr("Interpolated") output.destinationName = self.tr("Repaired profiles")
TOPO_BAT_EXPR = ( TOPO_BAT_EXPR = (
"'B' || replace(rpad('', num_points($geometry) - 1, ','), ',', ',B')" "'B' || replace(rpad('', num_points($geometry) - 1, ','), ',', ',B')"
) )
processing.run( outputs = {}
alg_params = {
"INPUT": parameters[self.INPUT],
"FIELDS_MAPPING": [
{
"expression": '"sec_id"',
"length": 0,
"name": "sec_id",
"precision": 0,
"type": 2,
},
{
"expression": '"sec_name"',
"length": 0,
"name": "sec_name",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_long"',
"length": 0,
"name": "abs_long",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_x"',
"length": 0,
"name": "axis_x",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_y"',
"length": 0,
"name": "axis_y",
"precision": 0,
"type": 6,
},
{
"expression": "''",
"length": 0,
"name": "layers",
"precision": 0,
"type": 10,
},
{
"expression": '"p_id"',
"length": 0,
"name": "p_id",
"precision": 0,
"type": 10,
},
{
"expression": TOPO_BAT_EXPR,
"length": 0,
"name": "topo_bat",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_lat"',
"length": 0,
"name": "abs_lat",
"precision": 0,
"type": 10,
},
{
"expression": '"zfond"',
"length": 0,
"name": "zfond",
"precision": 0,
"type": 10,
},
],
"OUTPUT": output,
# "OUTPUT": parameters[self.OUTPUT],
}
outputs["refactorfields"] = processing.run(
"native:refactorfields", "native:refactorfields",
{ alg_params,
"INPUT": layer, context=context,
"FIELDS_MAPPING": [ feedback=feedback,
{ is_child_algorithm=True,
"expression": '"sec_id"',
"length": 0,
"name": "sec_id",
"precision": 0,
"type": 2,
},
{
"expression": '"sec_name"',
"length": 0,
"name": "sec_name",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_long"',
"length": 0,
"name": "abs_long",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_x"',
"length": 0,
"name": "axis_x",
"precision": 0,
"type": 6,
},
{
"expression": '"axis_y"',
"length": 0,
"name": "axis_y",
"precision": 0,
"type": 6,
},
{
"expression": "''",
"length": 0,
"name": "layers",
"precision": 0,
"type": 10,
},
{
"expression": '"p_id"',
"length": 0,
"name": "p_id",
"precision": 0,
"type": 10,
},
{
"expression": TOPO_BAT_EXPR,
"length": 0,
"name": "topo_bat",
"precision": 0,
"type": 10,
},
{
"expression": '"abs_lat"',
"length": 0,
"name": "abs_lat",
"precision": 0,
"type": 10,
},
{
"expression": '"zfond"',
"length": 0,
"name": "zfond",
"precision": 0,
"type": 10,
},
],
"OUTPUT": output,
},
) )
return {self.OUTPUT: output} return {self.OUTPUT: outputs["refactorfields"]["OUTPUT"]}
def name(self): def name(self):
return "repair_profiles" return "repair_profiles"
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="http://ogr.maptools.org/"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:gmlsf="http://www.opengis.net/gmlsf/2.0"
elementFormDefault="qualified"
version="1.0">
<xs:annotation>
<xs:appinfo source="http://schemas.opengis.net/gmlsfProfile/2.0/gmlsfLevels.xsd">
<gmlsf:ComplianceLevel>0</gmlsf:ComplianceLevel>
</xs:appinfo>
</xs:annotation>
<xs:import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
<xs:import namespace="http://www.opengis.net/gmlsf/2.0" schemaLocation="http://schemas.opengis.net/gmlsfProfile/2.0/gmlsfLevels.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:AbstractFeature"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="featureMember">
<xs:complexType>
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureMemberType">
<xs:sequence>
<xs:element ref="gml:AbstractFeature"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="repair_profiles" type="ogr:repair_profiles_Type" substitutionGroup="gml:AbstractFeature"/>
<xs:complexType name="repair_profiles_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:CurvePropertyType" nillable="true" minOccurs="0" maxOccurs="1"/> <!-- restricted to LineString --><!-- srsName="urn:ogc:def:crs:EPSG::2154" -->
<xs:element name="sec_id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="sec_name" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="abs_long" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="axis_x" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="axis_y" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="layers" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="p_id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="topo_bat" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="abs_lat" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="zfond" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Source diff could not be displayed: it is too large. Options to address this: view the blob.
import os
from .. import (
DATA_PATH,
)
from . import TestCase
PROLFILES_2_0 = os.path.join(
DATA_PATH,
"input",
"engins",
"Modele_1959",
"Profils_modele_1959_v2.geojson",
)
class TestRepairProfilesAlgorithm(TestCase):
ALGORITHM_ID = "precourlis:repair_profiles"
DEFAULT_PARAMS = {
"INPUT": PROLFILES_2_0,
}
def test_algorithm_success(self):
self.check_algorithm({}, {"OUTPUT": "repair_profiles.gml"})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment