On Fri, 15 Jun 2007, David Hugh-Jones wrote:

> Hi R-spatialists,
>
> I'm working with a big list of polygons (imported into R with package
> sp as a SpatialPolygonDataFrame, and I am trying to calculate minimum
> distances between each pair of polygons. For this, I need to get the
> lines for each polygons. At the moment I can't seem to find a way to
> do this except to delve right in with
>
> for (p in [EMAIL PROTECTED]) {
>           for (q in [EMAIL PROTECTED])
>                       linesc <- rbind(linesc, coordinates(q))
>       }
>
> and then to add the endpoints of linesc as columns 3 and 4 of the
> matrix. Is there a simpler  way to extract lines from polygons?

No, this looks OK, though I would have said slot(spdfc, "polygons"), but 
there is no difference in practice. I would have kept the coordinates in a 
list of matrices rather than one matrix, in the first loop, because here 
you lose the polygon IDs.

You could go the way you are going now, then use the psp() and crossdist() 
functions in the spatstat package - they take single line segment 
patterns, so you'd need to break out the coordinates further to make psp 
objects, probably all in one shot.

I'd get the full matrix of distances, and retrieve the proper triangle by 
comparing pairs, which are not guaranteed to be equal - see the crossdist 
help page.

If you have geographical coordinates and world scale data, meaning you 
have to use Great Circle distances, the route via spapstat probably isn't 
viable. If you can project, you'd do that first, of course.

This is an interesting question, and I'm sure others would value hearing 
about your solution.

Best wishes,

Roger

>
> Cheers
> David
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@stat.math.ethz.ch
> 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: [EMAIL PROTECTED]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to