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

Allow handling geometry in CellularSpace #1335

Closed pedro-andrade-inpe closed 8 years ago

pedro-andrade-inpe commented 8 years ago

When geometry = true, CellularSpace reads the geometry but the user cannot handle it because the geometry is instantiated with TerraLib class Geometry, and not Point, Line, or Polygon. Fix it.

JoaoVitor123 commented 8 years ago
line = function(unitTest)
    local cs = CellularSpace{
        file = filePath("River_lin.shp", "terralib")
    }

    forEachCell(cs, function(cell)
        local NG = _Gtme.terralib_mod_binding_lua.te.gm.GeometryCollection.getNumGeometries(cell.geom)

        unitTest:assert(NG > 0)
        local geometry = cell.geom:getGeometryN(0)

        unitTest:assert(geometry ~= nil)
    end)
end,    

polygon = function(unitTest)
    local cs = CellularSpace{
        file = filePath("Limit_pol.shp", "terralib")
    }

    forEachCell(cs, function(cell)
        local NG = _Gtme.terralib_mod_binding_lua.te.gm.GeometryCollection.getNumGeometries(cell.geom)

        unitTest:assert(NG > 0)
        local geometry = cell.geom:getGeometryN(0)

        unitTest:assert(geometry ~= nil)
    end)
end
avancinirodrigo commented 8 years ago

The number of subtypes of geometry can be verified in this function:

local function getGeometryTypeName(geomType)
    if  geomType == binding.te.gm.GeometryType or 
        geomType == binding.te.gm.GeometryZType or
        geomType == binding.te.gm.GeometryMType or 
        geomType == binding.te.gm.GeometryZMType then
        return "geometry"
    elseif  geomType == binding.te.gm.PointType or
            geomType == binding.te.gm.PointZType or
            geomType == binding.te.gm.PointMType or
            geomType == binding.te.gm.PointZMType or
            geomType == binding.te.gm.PointKdType or
            geomType == binding.te.gm.MultiPointType or
            geomType == binding.te.gm.MultiPointZType or
            geomType == binding.te.gm.MultiPointMType or
            geomType == binding.te.gm.MultiPointZMType then         
        return "point"
    elseif  geomType == binding.te.gm.LineStringType or
            geomType == binding.te.gm.LineStringZType or
            geomType == binding.te.gm.LineStringMType or
            geomType == binding.te.gm.LineStringZMType or
            geomType == binding.te.gm.MultiLineStringType or
            geomType == binding.te.gm.MultiLineStringZType or
            geomType == binding.te.gm.MultiLineStringMType or
            geomType == binding.te.gm.MultiLineStringZMType then            
        return "line"
    elseif  geomType == binding.te.gm.CircularStringType or
            geomType == binding.te.gm.CircularStringZType or
            geomType == binding.te.gm.CircularStringMType or
            geomType == binding.te.gm.CircularStringZMType then
        return "circular"
    elseif  geomType == binding.te.gm.CompoundCurveType or
            geomType == binding.te.gm.CompoundCurveZType or
            geomType == binding.te.gm.CompoundCurveMType or
            geomType == binding.te.gm.CompoundCurveZMType then
        return "compound"
    elseif  geomType == binding.te.gm.PolygonType or
            geomType == binding.te.gm.PolygonZType or
            geomType == binding.te.gm.PolygonMType or
            geomType == binding.te.gm.PolygonZMType or
            geomType == binding.te.gm.CurvePolygonType or
            geomType == binding.te.gm.CurvePolygonZType or
            geomType == binding.te.gm.CurvePolygonMType or
            geomType == binding.te.gm.CurvePolygonZMType or
            geomType == binding.te.gm.MultiPolygonType or
            geomType == binding.te.gm.MultiPolygonZType or -- SKIP
            geomType == binding.te.gm.MultiPolygonMType or -- SKIP
            geomType == binding.te.gm.MultiPolygonZMType then -- SKIP       
        return "polygon"
    elseif  geomType == binding.te.gm.GeometryCollectionType or
            geomType == binding.te.gm.GeometryCollectionZType or -- SKIP
            geomType == binding.te.gm.GeometryCollectionMType or -- SKIP
            geomType == binding.te.gm.GeometryCollectionZMType then -- SKIP
        return "collection"                 
    elseif  geomType == binding.te.gm.MultiSurfaceType or
            geomType == binding.te.gm.MultiSurfaceZType or -- SKIP
            geomType == binding.te.gm.MultiSurfaceMType or -- SKIP
            geomType == binding.te.gm.MultiSurfaceZMType then -- SKIP
        return "surface"
    elseif  geomType == binding.te.gm.PolyhedralSurfaceType or
            geomType == binding.te.gm.PolyhedralSurfaceZType or -- SKIP
            geomType == binding.te.gm.PolyhedralSurfaceMType or -- SKIP
            geomType == binding.te.gm.PolyhedralSurfaceZMType then -- SKIP
        return "polyhedral" 
    elseif  geomType == binding.te.gm.TINType or
            geomType == binding.te.gm.TINZType or -- SKIP
            geomType == binding.te.gm.TINMType or -- SKIP
            geomType == binding.te.gm.TINZMType or -- SKIP
            geomType == binding.te.gm.TriangleType or -- SKIP
            geomType == binding.te.gm.TriangleZType or -- SKIP
            geomType == binding.te.gm.TriangleMType or -- SKIP
            geomType == binding.te.gm.TriangleZMType then -- SKIP
        return "triangle"       
    end  

    return "unknown"
end

@pedro-andrade-inpe and @JoaoVitor123, what types cast do you need?