Here is another method using rgeos..
The polygon geometry will be stored in a column and re-generated after the
data mapping is done

spP$WKT <- writeWKT(spP, byid=TRUE)

# I merge
spP.df <- as.data.frame(spP)
m <- merge(as.data.frame(spP), df, by.x="IDLOT", by.y="IDLOT")

# row names for m
IDs <- as.character(m$IDLOT)
for (i in levels(factor(IDs)))
{
      loc <- which(IDs==i); len = length(loc)
      IDs[loc] <- sapply(1:len, function(j) paste(IDs[loc][j], j, sep="."))
}
rownames(m) <- IDs

# SpatialPolygonsDataFrame
out <- vector(mode="list")
for (i in 1:nrow(m)) {
  out[[i]] <- readWKT(m$WKT[i], id = IDs[i], p4s = CRS("+init=EPSG:2154"))
}
save(out, file="out.RData")
r <- do.call("rbind", out)
spPdf <- SpatialPolygonsDataFrame(r, data = m)


All this is quite complex to do in R, but easier with PostgreSQL, except if
another method, simpler, exists?

Best,

Mathieu


2012/3/14 Mathieu Rajerison <mathieu.rajerison@gmail.com>

> Hi,
>
> Finally, I managed to do it. Here is how I processed. Maybe there was a
> simpler way. I had to build a SpatialPolygons from scratch..
>
> # On one side, I had a SpatialPolygonsDataFrame called spP
> # One the other side, a data frame called df
> spP <- readOGR(".", "LOTS")
>
> # I create a column IDGEOM:
> spP$IDGEOM <- 1:nrow(spP)
>
> # I merge spP and df
> spP.df <- as.data.frame(spP)
> m <- merge(spP.df,df, by.x="IDLOT", by.y="IDLOT")
>
> # Then, I give each line a unique id based on a numbered IDLOT
> # If the IDLOT 1320 appears twice (two owners for the lot), it will appear
> like this: 1320.1 then 1320.2
> # These IDs will be the Polygon IDs when I will build the SpatialPolygons
> object
> IDs <- as.character(m$IDLOT)
> for (i in levels(factor(IDs)))
> {
>       loc <- which(IDs==i); len = length(loc)
>       IDs[loc] <- sapply(1:len, function(j) paste(IDs[loc][j], j, sep="."))
> }
> rownames(m) <- IDs
>
> # Then, I create a Polygons List and finally the SpatialPolygonsDataFrame
> pl <- lapply(1:nrow(m), function(i) Polygons(slot(slot(spP,
> "polygons")[[m$IDGEOM[i]]], "Polygons"), ID=IDs[i]))
> spPdf <- SpatialPolygonsDataFrame(SpatialPolygons(pl), data = m)
>
>
> If anyone has a better idea or can make the code cleaner..
> There may be a way to do it a similar way with rgeos and WKT (?)
>
> Best,
>
> Mathieu
>
>
> 2012/3/14 Mathieu Rajerison <mathieu.rajerison@gmail.com>
>
>> Hi,
>>
>> I've already sent this e-mail to r-sig-geo@stat.math.ethz.ch, but the
>> correct email address may be r-sig-geo@r-project.org
>>
>> I have on one side geometries of lots that are unique
>> (spatialPolygonsDataFrame). On the other side, I have a huge file of owners
>> affected to each lot (data.frame).
>>
>> I know how to join one geometry to data with merge function, keeping row
>> names equivalent between geodata and data but here, as one lot can have
>> many owners, I need to duplicate the geometries when I meet many owners for
>> one lot.
>>
>> Is there a way to do so?
>>
>> Thanks in advance,
>>
>> Mathieu
>>
>
>

	[[alternative HTML version deleted]]

