0

I'm learning about use R to image processing. In this way, I'm trying to generate a polygon, which I will use top segment objects in a image. I've be trying some strategies and, in my searches, I found this post (SpatialPolygons - Creating a set of polygons in R from coordinates) which uses a similar strategy. trying to reproduce the results, with my data, I found a error. These are my steps. Take the coordinates, for example:

      [,1] [,2]
 [1,]  221  262
 [2,]  226  260
 [3,]  222  261
 [4,]  221  262
 [5,]  220  262
 [6,]  219  262
 [7,]  218  263
 [8,]  218  264
 [9,]  218  265
[10,]  218  266
[11,]  217  266
[12,]  217  267
[13,]  216  268
[14,]  216  269
[15,]  215  269
[16,]  215  270
[17,]  215  271
[18,]  216  272
[19,]  216  274
[20,]  216  275
[21,]  216  276
[22,]  216  277
[23,]  216  278
[24,]  217  279
[25,]  218  279
[26,]  219  279
[27,]  223  279
[28,]  224  279
[29,]  225  279
[30,]  226  279
[31,]  227  279
[32,]  228  279
[33,]  228  278
[34,]  231  278
[35,]  231  277
[36,]  232  277
[37,]  233  277
[38,]  233  276
[39,]  234  276
[40,]  235  276
[41,]  235  275
[42,]  236  275
[43,]  237  275
[44,]  237  274
[45,]  237  273
[46,]  238  273
[47,]  238  272
[48,]  239  272
[49,]  239  271
[50,]  239  270
[51,]  239  267
[52,]  239  266
[53,]  239  265
[54,]  240  265
[55,]  241  265
[56,]  241  264
[57,]  241  263
[58,]  241  262
[59,]  241  261
[60,]  241  260
[61,]  241  259
[62,]  241  258
[63,]  240  257
[64,]  239  257
[65,]  238  257
[66,]  237  257
[67,]  236  257
[68,]  235  257
[69,]  234  257
[70,]  233  257
[71,]  232  257
[72,]  231  258
[73,]  230  258
[74,]  229  258
[75,]  228  258
[76,]  227  258
[77,]  226  258
[78,]  226  259
[79,]  225  260
[80,]  224  261
[81,]  223  262
[82,]  221  262

I put these coordinates in a variable, p, and did:

   ps <- SpatialPolygons(list(Polygons(list(Polygon(p)),1)))

And the error returned was:

  Error in validObject(res) : 
   invalid class “SpatialPolygons” object: superclass "SpatialPolygonsNULL" not defined in the environment of the object's class

Anyone have any clue to solve this??

Thanks in advance

Community
  • 1
  • 1

0 Answers0