[SOLVED] polygon.read.format

If you have problems using RGeostats package or if you simply need some help on an unlisted subject.

[SOLVED] polygon.read.format

Postby Lochs » Wed Mar 11, 2020 3:01 am

I think there is a bug in the function `polygon.read.format()` (RGeoStats 11.2.12). For example:
Code: Select all
poly <- polygon.read.format('./shapefile')
Error in read.shapefile(filename) : object 'filename' not found

Looking at the function code it seems the local variable `filename` on line 6 is misnamed and should be `file` to match the function argument.
Code: Select all
polygon.read.format
function (file, mode = "shape")
{
    mode = toupper(mode)
    if (mode == "SHAPE") {
        if (requireNamespace("shapefiles", quietly = TRUE)) {
            shapefile = read.shapefile(filename)
            number = length(shapefile$shp$shp)
            poly = NA
            for (ipol in 1:number) {
                polyset = shapefile$shp$shp[[ipol]]
                poly = polygon.create(polyset$points[, 1], polyset$points[,
                  2], polygon = poly)
            }
        }
        else {
            cat("You must download the package 'shapefiles' first")
        }
    }
    else {
        cat("The only format available are:\n")
        cat("SHAPE   : ShapeFile Polygont format\n")
        stop0("Unknown format : ", mode)
    }
    poly
}
<bytecode: 0x7fd564308438>
<environment: namespace:RGeostats>

Edit: Replacing the local variable name fixed the issue for me and function runs as intended.
Lochs
 
Posts: 2
Joined: Wed Mar 11, 2020 2:52 am

Re: [BUG] polygon.read.format

Postby Didier Renard » Sun Mar 15, 2020 4:27 pm

Thanks for the correction
Didier Renard
 
Posts: 337
Joined: Thu Sep 20, 2012 4:22 pm


Return to Other Troubleshooting

Who is online

Users browsing this forum: No registered users and 5 guests

cron