RSAGA Vectorizing Grid Classes creates unclosed rings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

RSAGA Vectorizing Grid Classes creates unclosed rings

manuel.schneider
Dear list

I am trying to use SAGA function Vectorizing grid classes from R but
this creates an unclosed ring in the resulting shapefile. All steps work
in SAGA GUI. Maybe somebody can reproduce the error and help on it.
Otherwise, is there a direct way (in the sp framework) to convert grid
classes into polygons?

> d <- SpatialGridDataFrame(GridTopology(c(0,0), c(1,1), c(5,6)),
data=data.frame(x=sample(rep(c(NA,1,2),10),30)))
> write.asciigrid(d, "test.asc" , na.value=-9999)
> rsaga.esri.to.sgrd(in.grids="test.asc", out.sgrd="classes.sgrd")

SAGA CMD 2.0.3
library path:   C:/ManuProgs/R/R-2.10.1/library/RSAGA/saga_vc/modules
library name:   io_grid
module name :   Import ESRI Arc/Info Grid
author      :   (c) 2007 by O.Conrad
Parameters
Grid: [not set]
File: test.asc
ready
Save grid: classes.sgrd...
ready

> rsaga.geoprocessor(lib="shapes_grid", module=6,
param=list(GRID="classes.sgrd", SHAPES="classes.shp", CLASS_ALL=1))

SAGA CMD 2.0.3
library path:   C:/ManuProgs/R/R-2.10.1/library/RSAGA/saga_vc/modules
library name:   shapes_grid
module name :   Vectorising Grid Classes
author      :   (c) 2008 by O.Conrad
Load grid: classes.sgrd...
ready
Parameters
Grid system: 1; 5x 6y; 0x 0y
Grid: classes.sgrd
Shapes: Shapes
Class Selection: all classes
Class Identifier: 1.000000
Vectorised class as...: each island as separated polygon

vectorising class 1: 1.000000
vectorising class 2: 2.000000
Save shapes: classes.shp...
Save shapes: classes.shp
ready
Save table: classes.dbf...
ready

> classes <- readOGR("classes.shp","classes")
OGR data source with driver: ESRI Shapefile
Source: "classes.shp", layer: "classes"
with 8 features and 3 fields
Feature type: wkbPolygon with 2 dimensions
Error in is.vector(X) : ring not closed

Thanks in advance
Manuel

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: RSAGA Vectorizing Grid Classes creates unclosed rings

Roger Bivand
Administrator
On Tue, 11 May 2010, [hidden email] wrote:

> Dear list
>
> I am trying to use SAGA function Vectorizing grid classes from R but
> this creates an unclosed ring in the resulting shapefile. All steps work
> in SAGA GUI. Maybe somebody can reproduce the error and help on it.
> Otherwise, is there a direct way (in the sp framework) to convert grid
> classes into polygons?
>
>> d <- SpatialGridDataFrame(GridTopology(c(0,0), c(1,1), c(5,6)),
> data=data.frame(x=sample(rep(c(NA,1,2),10),30)))
>> write.asciigrid(d, "test.asc" , na.value=-9999)
>> rsaga.esri.to.sgrd(in.grids="test.asc", out.sgrd="classes.sgrd")
>
> SAGA CMD 2.0.3
> library path:   C:/ManuProgs/R/R-2.10.1/library/RSAGA/saga_vc/modules
> library name:   io_grid
> module name :   Import ESRI Arc/Info Grid
> author      :   (c) 2007 by O.Conrad
> Parameters
> Grid: [not set]
> File: test.asc
> ready
> Save grid: classes.sgrd...
> ready
>
>> rsaga.geoprocessor(lib="shapes_grid", module=6,
> param=list(GRID="classes.sgrd", SHAPES="classes.shp", CLASS_ALL=1))
>
> SAGA CMD 2.0.3
> library path:   C:/ManuProgs/R/R-2.10.1/library/RSAGA/saga_vc/modules
> library name:   shapes_grid
> module name :   Vectorising Grid Classes
> author      :   (c) 2008 by O.Conrad
> Load grid: classes.sgrd...
> ready
> Parameters
> Grid system: 1; 5x 6y; 0x 0y
> Grid: classes.sgrd
> Shapes: Shapes
> Class Selection: all classes
> Class Identifier: 1.000000
> Vectorised class as...: each island as separated polygon
>
> vectorising class 1: 1.000000
> vectorising class 2: 2.000000
> Save shapes: classes.shp...
> Save shapes: classes.shp
> ready
> Save table: classes.dbf...
> ready
>
>> classes <- readOGR("classes.shp","classes")
> OGR data source with driver: ESRI Shapefile
> Source: "classes.shp", layer: "classes"
> with 8 features and 3 fields
> Feature type: wkbPolygon with 2 dimensions
> Error in is.vector(X) : ring not closed

http://shapelib.maptools.org/dl/shapefile.pdf

does specify that a polygon in a shapefile must be closed. You may be able
to use readShapePoly(..., force_ring=TRUE) in maptools to work around the
problem.

Roger

>
> Thanks in advance
> Manuel
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: RSAGA Vectorizing Grid Classes creates unclosed rings

manuel.schneider
Roger Bivand <Roger.Bivand <at> nhh.no> writes:

>
> On Tue, 11 May 2010, manuel.schneider <at> art.admin.ch wrote:
>
...

> > Error in is.vector(X) : ring not closed
>
> http://shapelib.maptools.org/dl/shapefile.pdf
>
> does specify that a polygon in a shapefile must be closed. You may be able
> to use readShapePoly(..., force_ring=TRUE) in maptools to work around the
> problem.
>
> Roger
>
>

As always, your suggestion does the trick. Thanks a lot.
However, still puzzled why it occurs.

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: RSAGA Vectorizing Grid Classes creates unclosed rings

Johan Van de Wauw
This is a known error in SAGA.
It will be fixed in the next version
http://saga-gis.cvs.sourceforge.net/viewvc/saga-gis/saga_2/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.cpp?view=log

On Tue, May 11, 2010 at 8:02 PM, manuel.schneider
<[hidden email]> wrote:

> Roger Bivand <Roger.Bivand <at> nhh.no> writes:
>
>>
>> On Tue, 11 May 2010, manuel.schneider <at> art.admin.ch wrote:
>>
> ...
>> > Error in is.vector(X) : ring not closed
>>
>> http://shapelib.maptools.org/dl/shapefile.pdf
>>
>> does specify that a polygon in a shapefile must be closed. You may be able
>> to use readShapePoly(..., force_ring=TRUE) in maptools to work around the
>> problem.
>>
>> Roger
>>
>>
>
> As always, your suggestion does the trick. Thanks a lot.
> However, still puzzled why it occurs.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo