Dear all,


After playing around with the tessellation functions of the spatstat
package to reply to a previous question on the list, I realized that there
seems to be something odd when converting from tess format to spatial
polygon format.

Usually, spatial polygonal shapefiles read into R with functions like
readShapePoly or readOGR, are objects which have a slot called "data", that
can be assessed with @data and has the format of a data.frame. In there,
each polygonal feature of the map is a row, while the columns are the
variables that are eventually present in the shapefiles's data. Therefore,
if you try to check names() of a spatial polygon object read from a
shapefile, you get these columns, while row() gives you the polygon
features present in the map.

However, when converting a tess object generated by spatstat to shape
polygon, by using the as( , "SpatialPolygons"), things look quite
different. First, no slot called data is created. Second, if you try
names() on the converted object, you will get each polygon features and
with row(), you get nothing. This looks odd, since the features should be
the rows of a data.frame-like slot, shouldn't them?

Here it goes a reproducible example:

###Code begins here

#Let's first read a shp map for comparison

vectors.path <- system.file("vectors", package = "rgdal")[1]
loaded.map <- readShapePoly(paste(vectors.path, "/scot_BNG.shp", sep=""))
plot(loaded.map)      #looking at the loaded map
class(loaded.map)      #checking if it is of the class we want

#Now let's generate a shp map from tessellation

randompoints <- rpoint(100)      #generate random spatial points
random.map.tess <- dirichlet(randompoints)      #tessellate the points
random.map <- as(random.map.tess, "SpatialPolygons")      #convert to shape
polygon
plot(random.map)      #looking at the random generated map
class(random.map)      #checking if it is of the class we want


#Finally, let's compare both polygon shape objects:

names(loaded.map)
names(random.map)

row(loaded.map)
row(random.map)

nrow(loaded.map)
nrow(random.map)

ncol(loaded.map)
ncol(random.map)

View(loaded.map@data)
View(random.map@data)

###End of code


Notice how things look different for the same sp objects when loading them
or creating from a tess converted object.  I mean, I am not sure whether
this is really a bug or it is normal and if yes, why does it happen (that's
why the subject of this email is a question, not an affirmative sentence),
but I though it was worth bringing to you all since it can be confusing.
Anyway, is there any way we can convert tess objects to a sp object in the
pattern a shapefile map is read, i.e. with the "data" slot and with the
polygon features as rows, no as columns?

As always, thank you all for your time.

Best,

Fabricio Vasselai
CPS-University of Michigan
University of São Paulo

	[[alternative HTML version deleted]]

