Hi Mike.

Thanks a lot! It helped one step further.

I understand that this: "lapply(p@polygons, function(x)
dim(x@Polygons[[1]]@coords))"
gives me the number of points per polygon, and that xy is a table of all
coordinates. So if for example the first value in the lapply above is 14,
then the first 14 rows of xy belong to polygon 1. How can I efficiently add
a third column to add the polygon number per coordinate pair?

Best Regards,
/Chris

On Wed, Feb 29, 2012 at 5:44 PM, Michael Sumner <mdsumner@gmail.com> wrote:

> Sorry, that should have been "x@y" for the raw access to S4 elements.
>
> On Thu, Mar 1, 2012 at 7:44 AM, Michael Sumner <mdsumner@gmail.com> wrote:
> > You can do this:
> >
> > https://stat.ethz.ch/pipermail/r-sig-geo/2010-February/007619.html
> >
> > (The email archive, or my browser has auto-converted "x @ y" symbols
> > to "x at y" rather helpfully so you will need to fix that if that's
> > what you see).
> >
> > The fortify tools (in ggplot2) and the geometry/topology-sense in
> > rgeos are important to consider though, fortify is trying to build a
> > table that still stores all the topology so that (for e.g.) ggplot2
> > can work with it in a standard way.
> >
> > Raw extraction does not take any care with whether the polygons make
> > sense, but that takes work since shapefiles just don't store that
> > information, they are just sets of ring boundaries and it's up to the
> > software using them to build the actual topology. My code at that post
> > just drops the final duplicated coordinate . . .
> >
> > Cheers, Mike.
> >
> > On Thu, Mar 1, 2012 at 5:15 AM, Christian Jansson <chrjan70@gmail.com>
> wrote:
> >> Hi,
> >>
> >> Thanks to everyone on this list. It is a true source of help!
> >>
> >> I'm reading huge shapefiles like this:
> >>
> >> shp_0 <- rgdal::readOGR(dsn="dir", layer="TheLayer")
> >>
> >> There are two columns in the shp_0@data: bin1 and bin2.
> >>
> >> I need to get a table with three columns: id, X, Y.
> >>
> >> First I do this:
> >> shp_0@data$id = rownames(shp_0@data)
> >>
> >> When I then run this:
> >> tbl_coords <-fortify.SpatialPolygonsDataFrame(shp_0)
> >> I get: "Using bin1 to define regions.
> >> Error in createPolygonsComment(p) :
> >>  rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon
> >> for hole at index 3"
> >>
> >> After reading in previous messages on this email-list, I tried:
> >>
> >> slot(shp_0, "polygons") <- lapply(slot(shp_0, "polygons"),
> >> checkPolygonsHoles), which proceeds to a new R-prompt with no issue
> >> mentioned.
> >>
> >> But everytime I then run
> >> shp_1 <- unionSpatialPolygons(shp_0, as.character(shp_0$id))
> >> I get another crasch:
> >> "This application has requested the Runtime to terminate it in an
> unusual
> >> way.
> >> Please contact the application's support team for more information."
> >>
> >> How can I get the coordinates per polygon in one large table? I know
> how to
> >> get them per polygon, but to rbind more than 30 000 polygons take
> forever.
> >> To get the areas is easy "sapply(shp_0@polygons, function(x) x@area)",
> but
> >> the coords are deeper into the sp-object and I don't know how to
> "apply-it
> >> out".
> >>
> >> Thank you very much for all help.
> >>
> >> /Chris
> >>
> >>        [[alternative HTML version deleted]]
> >>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo@r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> >
> >
> > --
> > Michael Sumner
> > Institute for Marine and Antarctic Studies, University of Tasmania
> > Hobart, Australia
> > e-mail: mdsumner@gmail.com
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner@gmail.com
>

	[[alternative HTML version deleted]]

