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

save a subset of a shapefile #1824

Closed pedro-andrade-inpe closed 7 years ago

pedro-andrade-inpe commented 7 years ago

Allow TerraME to save a subset of a shapefile, such as in the script below. Additionally, the file saved should be placed in the current directory.


import("terralib")

project = Project{
    file = "save.tview",
    clean = true,
    estados = filePath("br_states.shp", "publish")
}

cs = CellularSpace{
    project = project,
    layer = "estados",
    geometry = true
}

t = Trajectory{
    target = cs,
    select = function(cell)
        return cell.SIGLAUF3 == "MT"
    end
}

print(#t)
mt = t.cells[1]

t2 = Trajectory{
    target = cs,
    select = function(cell)
        print(cell.SIGLAUF3.."\t"..tostring(mt.geom:touches(cell.geom)))
        return mt.geom:touches(cell.geom)

    end
}

print(#t2)

TerraLib().saveDataSet(project, "estados", t2.cells, "subestados", {"OGR_GEOMETRY", "SIGLAUF3"}, "subst")
pedro-andrade-inpe commented 7 years ago

This issue is necessary to solve #1861.

avancinirodrigo commented 7 years ago

@pedro-andrade-inpe I think that TerraLib objects must not handled by users, because it uses C++ pointer and it can result in a lot of problems. I suggested a new type for handle Geometry for work with safe code (encapsulation).

avancinirodrigo commented 7 years ago

For internal things, there is no problem.

pedro-andrade-inpe commented 7 years ago

The final user will execute the functionality implemented by #1861.