diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.cpg b/packages/gis/data/test/cs_cerrado_clip_29101.cpg new file mode 100644 index 00000000..3ad133c0 --- /dev/null +++ b/packages/gis/data/test/cs_cerrado_clip_29101.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.dbf b/packages/gis/data/test/cs_cerrado_clip_29101.dbf new file mode 100644 index 00000000..b0333d01 Binary files /dev/null and b/packages/gis/data/test/cs_cerrado_clip_29101.dbf differ diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.prj b/packages/gis/data/test/cs_cerrado_clip_29101.prj new file mode 100644 index 00000000..2a1ed23c --- /dev/null +++ b/packages/gis/data/test/cs_cerrado_clip_29101.prj @@ -0,0 +1 @@ +PROJCS["SAD69_Brazil_Polyconic",GEOGCS["GCS_SAD69",DATUM["D_South_American_1969",SPHEROID["GRS_1967_Truncated",6378160,298.25]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Polyconic"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-54],PARAMETER["false_easting",5000000],PARAMETER["false_northing",10000000],UNIT["Meter",1]] \ No newline at end of file diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.qpj b/packages/gis/data/test/cs_cerrado_clip_29101.qpj new file mode 100644 index 00000000..3f4bb25d --- /dev/null +++ b/packages/gis/data/test/cs_cerrado_clip_29101.qpj @@ -0,0 +1 @@ +PROJCS["SAD69 / Brazil Polyconic",GEOGCS["SAD69",DATUM["South_American_Datum_1969",SPHEROID["GRS 1967 Modified",6378160,298.25,AUTHORITY["EPSG","7050"]],TOWGS84[-66.87,4.37,-38.52,0,0,0,0],AUTHORITY["EPSG","6618"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4618"]],PROJECTION["Polyconic"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-54],PARAMETER["false_easting",5000000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","29101"]] diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.shp b/packages/gis/data/test/cs_cerrado_clip_29101.shp new file mode 100644 index 00000000..c845d4b8 Binary files /dev/null and b/packages/gis/data/test/cs_cerrado_clip_29101.shp differ diff --git a/packages/gis/data/test/cs_cerrado_clip_29101.shx b/packages/gis/data/test/cs_cerrado_clip_29101.shx new file mode 100644 index 00000000..ba50d9f5 Binary files /dev/null and b/packages/gis/data/test/cs_cerrado_clip_29101.shx differ diff --git a/packages/gis/data/test/prodes_cerrado_clip_nodata_100_proj_29101.tif b/packages/gis/data/test/prodes_cerrado_clip_nodata_100_proj_29101.tif new file mode 100644 index 00000000..fbd950ce Binary files /dev/null and b/packages/gis/data/test/prodes_cerrado_clip_nodata_100_proj_29101.tif differ diff --git a/packages/gis/lua/TerraLib.lua b/packages/gis/lua/TerraLib.lua index 3887d33d..fd197b99 100644 --- a/packages/gis/lua/TerraLib.lua +++ b/packages/gis/lua/TerraLib.lua @@ -722,9 +722,9 @@ local function createProgressViewer(msg) end end -local function finalizeProgressViewer(viewerId) +local function finalizeProgressViewer() --(viewerId) if progress then - binding.te.common.ProgressManager.getInstance():removeViewer(viewerId) -- SKIP + binding.te.common.ProgressManager.getInstance():clearAll() -- SKIP TODO: removeViewer(viewerId) seems not working end end @@ -3630,51 +3630,25 @@ TerraLib_ = { loadProject(project, project.file) local layer = project.layers[layerName] - local dsInfo = binding.te.da.DataSourceInfoManager.getInstance():getDsInfo(layer:getDataSourceId()) - local ds = makeAndOpenDataSource(dsInfo:getConnInfo(), dsInfo:getType()) - local dseName = layer:getDataSetName() - local dse = ds:getDataSet(dseName) - local dst = ds:getDataSetType(dseName) - local oids = binding.te.da.ObjectIdSet():clone() - local pk = dst:getPrimaryKey() - local pkName - if pk then - pkName = pk:getPropertyName(0) - local pkPos = dst:getPropertyPosition(pkName) - local pkType = pk:getProperty(pkPos):getType() - oids:addProperty(pkName, pkPos, pkType) - end + local viewerId = createProgressViewer("Checking '"..layerName.."' geometries") + local geomError = binding.CheckLayerGeometries(layer) + finalizeProgressViewer(viewerId) - if dst:hasGeom() then - local gp = binding.GetFirstGeomProperty(dst) - local gname = gp:getName() - local gpos = getPropertyPosition(dse, gname) - - dse:moveBeforeFirst() - while dse:moveNext() do - local geom = dse:getGeom(gpos) - local err = binding.TopologyValidationError() - if not binding.CheckValidity(geom, err) then - if pk then - local oid = binding.te.da.ObjectId():clone() - oid:addValue(dse:getValue(pkName):clone()) - oids:add(oid) - table.insert(problems, {pk = {name = pkName, value = dse:getAsString(pkName)}, - error = err.m_message, - coord = {x = err.m_coordinate:getX(), y = err.m_coordinate:getY()}}) - else - table.insert(problems, {error = err.m_message, --SKIP - coord = {x = err.m_coordinate:getX(), y = err.m_coordinate:getY()}}) --SKIP - end - end - end + local problemsInfo = geomError:getProblems() - if fix and (#problems > 0) then - local viewerId = createProgressViewer("Fixing '"..layerName.."' geometries") - fixErrorMsg = binding.te.vp.MakeGeometryValid.makeValid(layer, dseName, oids) - finalizeProgressViewer(viewerId) - end + for i = 0, getn(problemsInfo) - 1 do + local problem = problemsInfo[i] + table.insert(problems, {pk = {name = problem.propertyName, value = problem.propertyValue}, + error = problem.errorMsg, + coord = {x = problem.coordX, y = problem.coordY}}) + end + + if fix and (#problems > 0) then + viewerId = createProgressViewer("Fixing '"..layerName.."' geometries") + fixErrorMsg = binding.te.vp.MakeGeometryValid.makeValid(layer, + layer:getDataSetName(), geomError.objectIdSet) + finalizeProgressViewer(viewerId) end releaseProject(project) diff --git a/packages/gis/tests/functional/basic/Project.lua b/packages/gis/tests/functional/basic/Project.lua index d808bc4f..6b0ff988 100644 --- a/packages/gis/tests/functional/basic/Project.lua +++ b/packages/gis/tests/functional/basic/Project.lua @@ -245,7 +245,7 @@ return { directory = packageInfo("gis").data.."test" } - unitTest:assertEquals(getn(proj.layers), 23) + unitTest:assertEquals(getn(proj.layers), 25) file:deleteIfExists() local version = "" diff --git a/packages/gis/tests/tif/basic/Layer.lua b/packages/gis/tests/tif/basic/Layer.lua index ac9fff6d..89ab6751 100644 --- a/packages/gis/tests/tif/basic/Layer.lua +++ b/packages/gis/tests/tif/basic/Layer.lua @@ -552,8 +552,59 @@ return { proj.file:delete() end + local coverageWithDummy = function() + local csFile = filePath("test/cs_cerrado_clip_29101.shp", "gis") + csFile:copy(currentDir()) + + local proj = Project{ + file = "layer_fill_shp_basic.tview", + clean = true + } + + local prodes = Layer { + project = proj, + name = "Prodes", + file = filePath("test/prodes_cerrado_clip_nodata_100_proj_29101.tif", "gis"), + epsg = 29101 + } + + local cl = Layer { + project = proj, + name = "Cells", + file = "cs_cerrado_clip_29101.shp" + } + + cl:fill{ + operation = "coverage", + layer = prodes.name, + attribute = "cov1", + progress = false + } + + cl:fill{ + operation = "coverage", + layer = prodes.name, + attribute = "cov2", + dummy = 1000, + progress = false + } + + local cs = CellularSpace{ + project = proj, + layer = cl.name + } + + local cell = cs:get("3") + unitTest:assertNil(cell.cov1_100) + unitTest:assertEquals(cell.cov2_100, 0.65175164758932, 1e-14) + + cl:delete() + proj.file:delete() + end + unitTest:assert(allSupportedOperation) unitTest:assert(coverageTotalArea) + unitTest:assert(coverageWithDummy) end, representation = function(unitTest) local projName = "layer_fill_tiff_repr.tview" diff --git a/packages/gis/tests/tif/basic/TerraLib.lua b/packages/gis/tests/tif/basic/TerraLib.lua index e6e26238..52b73b0b 100644 --- a/packages/gis/tests/tif/basic/TerraLib.lua +++ b/packages/gis/tests/tif/basic/TerraLib.lua @@ -545,7 +545,89 @@ return { proj.file:delete() end + local coverageWithDummy = function() + local proj = { + file = "attrfill-tif-basic.tview", + title = "TerraLib Tests", + author = "Avancini Rodrigo" + } + + File(proj.file):deleteIfExists() + TerraLib().createProject(proj, {}) + + local csFile = filePath("test/cs_cerrado_clip_29101.shp", "gis") + csFile:copy(currentDir()) + + local l1Name = "Cells" + local l1File = File("cs_cerrado_clip_29101.shp") + TerraLib().addShpLayer(proj, l1Name, l1File) + + local l1Info = TerraLib().getLayerInfo(proj, l1Name) + + local l2Name = "Prodes" + local l2File = filePath("test/prodes_cerrado_clip_nodata_100_proj_29101.tif", "gis") + TerraLib().addGdalLayer(proj, l2Name, l2File, l1Info.srid) + + local l3Name = "cells_cov_dummy" + local l3File = File(l3Name..".shp") + local operation = "coverage" + local attribute = "cov" + local select = 0 + local default = 0 + local pixel = false + local nodata = TerraLib().getDummyValue(proj, l2Name, 0) + + l3File:deleteIfExists() + TerraLib().attributeFill{ + project = proj, + from = l2Name, + to = l1Name, + out = l3Name, + attribute = attribute, + operation = operation, + select = select, + area = area, + default = default, + repr = "raster", + pixel = pixel, + nodata = nodata + } + + local l3Set = TerraLib().getDataSet{project = proj, layer = l3Name} + + unitTest:assertNil(l3Set[0].cov_100) + + local l4Name = "cells_cov_nodummy" + local l4File = File(l4Name..".shp") + + l4File:deleteIfExists() + TerraLib().attributeFill{ + project = proj, + from = l2Name, + to = l1Name, + out = l4Name, + attribute = attribute, + operation = operation, + select = select, + area = area, + default = default, + repr = "raster", + pixel = pixel, + nodata = 1000 + } + + local l4Set = TerraLib().getDataSet{project = proj, layer = l4Name} + + unitTest:assertEquals(l4Set[0].cov_100, 0.90114464099896, 1e-14) + + l1File:delete() + l3File:delete() + l4File:delete() + proj.file:delete() + end + unitTest:assert(coverageTotalArea) + unitTest:assert(coverageWithDummy) end }