3

I have a Model that I use to filter a chain of points that have extracted values form a DEM (digital elevation model). I want to smoothen the hights with a filter that takes the average of the previous and following points and checks if the elevation is higher than a certain threshold.

I have already worked out the two field calculator steps I need to do and when I just put one of them in the model builder it will work fine. So original file as input for filt_1 and save output 1. Output 1 as input for filt_2 and then getting the right output. When I chain them, the second one will fail.

I have the feeling that for the second algorithm get_feature_by_id is not working properly, so the IF condition will always be False and so z1 will be taken. I also tried to set filt_1 as parent algorithm for filt_2, but it's not changing.

Is this a bug or am I just missing something?

I added some points to test in GeoJSON format as well.

Comments:

  • The else value of the most inner IF will be z1, just using the condition as output to see if it works here.

  • z1 will be generated by filt_1.

Model The algorithm I use for filt_1 is and it works fine:

IF( $id < 3, DGM , 
    IF( $id > count( 0 ) - 2, DGM ,
        IF(
                ( DGM -
                    (
                        (
                            attribute( get_feature_by_id(@layer_id, $id - 2 ), 'DGM' ) + 
                            attribute( get_feature_by_id(@layer_id, $id - 1 ), 'DGM' ) + 
                            attribute( get_feature_by_id(@layer_id, $id + 1 ), 'DGM' ) + 
                            attribute( get_feature_by_id(@layer_id, $id + 2 ), 'DGM' ) 
                        ) / 4 
                    ) 
                ) > 0.5 , 
            ( 
                (
                    attribute( get_feature_by_id(@layer_id, $id - 2 ), 'DGM' ) + 
                    attribute( get_feature_by_id(@layer_id, $id - 1 ), 'DGM' ) + 
                    attribute( get_feature_by_id(@layer_id, $id + 1 ), 'DGM' ) + 
                    attribute( get_feature_by_id(@layer_id, $id + 2 ), 'DGM' ) 
                ) / 4 
            ) , 
            DGM 
        )
    )
)

The algorithm in filt2, that is not working, is:

IF( $id < 3, z1 , 
    IF( $id > count( 0 ) - 2, z1 , 
        IF(
            ( z1 - 
                ( 
                    (
                        attribute( get_feature_by_id(@layer_id, $id - 2 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id - 1 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id + 1 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id + 2 ), 'z1' ) 
                    ) / 4 
                ) 
            ) > 0.3,
            (
                attribute( get_feature_by_id(@layer_id, $id - 2 ), 'z1' ) + 
                attribute( get_feature_by_id(@layer_id, $id - 1 ), 'z1' ) + 
                attribute( get_feature_by_id(@layer_id, $id + 1 ), 'z1' ) + 
                attribute( get_feature_by_id(@layer_id, $id + 2 ), 'z1' ) 
            ) / 4,
            ( z1 - 
                ( 
                    (
                        attribute( get_feature_by_id(@layer_id, $id - 2 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id - 1 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id + 1 ), 'z1' ) + 
                        attribute( get_feature_by_id(@layer_id, $id + 2 ), 'z1' ) 
                    ) / 4 
                ) 
            )
        )
    )
)

GeoJSON file:

    {
"type": "FeatureCollection",
"name": "test",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::31468" } },
"features": [
{ "type": "Feature", "properties": { "DGM": 380.23999, "ID": 0 }, "geometry": { "type": "Point", "coordinates": [ -111.975560781545937, 73.679535304196179 ] } },
{ "type": "Feature", "properties": { "DGM": 380.20001, "ID": 1 }, "geometry": { "type": "Point", "coordinates": [ -107.757253343239427, 76.363912765868008 ] } },
{ "type": "Feature", "properties": { "DGM": 380.25, "ID": 2 }, "geometry": { "type": "Point", "coordinates": [ -103.538945904001594, 79.048290226608515 ] } },
{ "type": "Feature", "properties": { "DGM": 380.04001, "ID": 3 }, "geometry": { "type": "Point", "coordinates": [ -99.320638465695083, 81.732667687349021 ] } },
{ "type": "Feature", "properties": { "DGM": 380.10001, "ID": 4 }, "geometry": { "type": "Point", "coordinates": [ -95.10233102645725, 84.417045148089528 ] } },
{ "type": "Feature", "properties": { "DGM": 380.23001, "ID": 5 }, "geometry": { "type": "Point", "coordinates": [ -90.880096898414195, 87.095154268667102 ] } },
{ "type": "Feature", "properties": { "DGM": 380.89999, "ID": 6 }, "geometry": { "type": "Point", "coordinates": [ -86.624093773774803, 89.719356508925557 ] } },
{ "type": "Feature", "properties": { "DGM": 381.26999, "ID": 7 }, "geometry": { "type": "Point", "coordinates": [ -82.368090648204088, 92.343558749184012 ] } },
{ "type": "Feature", "properties": { "DGM": 380.12, "ID": 8 }, "geometry": { "type": "Point", "coordinates": [ -78.112087522633374, 94.967760989442468 ] } },
{ "type": "Feature", "properties": { "DGM": 380.13, "ID": 9 }, "geometry": { "type": "Point", "coordinates": [ -73.856084397062659, 97.5919632287696 ] } },
{ "type": "Feature", "properties": { "DGM": 380.13, "ID": 10 }, "geometry": { "type": "Point", "coordinates": [ -69.600081272423267, 100.216165469028056 ] } },
{ "type": "Feature", "properties": { "DGM": 380.07999, "ID": 11 }, "geometry": { "type": "Point", "coordinates": [ -65.344078146852553, 102.840367709286511 ] } },
{ "type": "Feature", "properties": { "DGM": 380.09, "ID": 12 }, "geometry": { "type": "Point", "coordinates": [ -61.088075021281838, 105.464569949544966 ] } },
{ "type": "Feature", "properties": { "DGM": 380.14999, "ID": 13 }, "geometry": { "type": "Point", "coordinates": [ -56.832071895711124, 108.088772189803421 ] } }
]
}
  • I'm having a similar problem. Did you find a solution? – Mateo Aug 18 at 5:15
  • It is a known issue as it seems. I made a bug report that changed to a feature request now. github.com/qgis/QGIS/issues/30397 – JBecker Sep 19 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.