[R-sig-Geo] newbie sp question

David Hugh-Jones d-hugh-jones at northwestern.edu
Sun Jun 17 00:51:04 CEST 2007


Thank you for this help. I realised after writing this that indeed,
spatstat won't work because I have world-scale data in unprojected
latitude/longitude form... so my distance measure is no use. This
leads to more questions

- is there a canonical way to convert projections from within "sp"? My
current thought is to get the raw data out and use "mapproj".
- when that's done, is there a function to measure great circle distance?
- would the algorithm "measure distance between all points of A and
all lines of B, then the same with A and B reversed, and take the
minimum", still work? I can't see why not but my intuition is not
clear.

Cheers
David


On 16/06/07, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> 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 spdfc at polygons) {
> >           for (q in p at Polygons)
> >                       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 at 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: Roger.Bivand at nhh.no
>




More information about the R-sig-Geo mailing list