TerraME / terrame

TerraME is a programming environment for spatial dynamical modelling
www.terrame.org
GNU Lesser General Public License v3.0
36 stars 13 forks source link

count operation of fill function has null values #1829

Closed vilmount closed 7 years ago

vilmount commented 7 years ago

The default value for the count operation is null, not 0.

cs:fill{ layer = "teste", operation = "count", attribute = "rodcount" }

pedro-andrade-inpe commented 7 years ago

Strange. The test for windows looks fine: https://github.com/TerraME/terrame/blob/master/packages/terralib/log/windows/lines-count.png

@vilmount, can you provide a script and data to reproduce such problem?

vilmount commented 7 years ago

My result image

pedro-andrade-inpe commented 7 years ago

The script creates attribute "rodcount", while the image has attribute "apcount". Anyway, I need script and data in order to reproduce such problem.

avancinirodrigo commented 7 years ago

It seems associated to default argument.

avancinirodrigo commented 7 years ago

There is no default for count.

pedro-andrade-inpe commented 7 years ago

You are right:

            count = function()
                if belong(repr, {"point", "line", "polygon", "surface"}) then
                    verifyUnnecessaryArguments(data, {"attribute", "layer", "operation"})
                    data.select = "FID"
                else
                    customError("The operation '"..data.operation.."' is not available for layers with "..repr.." data.") -- SKIP
                end
            end,

Just set the default value of default to zero and check the images in the log directory. The only strange point is why it is shown as zero in the logs.

This issue might be related to #1784 (although the other one is a PostGIS problem).

avancinirodrigo commented 7 years ago

@pedro-andrade-inpe, I guess that there is another problema here beyond the default. The count operation creates a data with null values, but Map is coloring as 0. test/shapefile/Layer.lua

        clamaz:fill{
            operation = "count",
            layer = portos,
            attribute = "pointcount"
        }

        cs = CellularSpace{
            project = proj,
            layer = clamaz.name
        }

        map = Map{
            target = cs,
            select = "pointcount",
            value = {0, 1, 2},
            color = {"green", "red", "blue"}
        }
pedro-andrade-inpe commented 7 years ago

When a cellularspace is loaded, how null values are read?

avancinirodrigo commented 7 years ago

@pedro-andrade-inpe Currently, terralib returns the value as 0, but it is possible to check if the value is null, however, if a value is set as nil in a table, the key is removed.
What would be the solution for it?

pedro-andrade-inpe commented 7 years ago

Solved by https://github.com/TerraME/terrame/pull/1835/commits/073a8762788e6a2eabb261253f7c0b381120f06a.