[R-sig-Geo] [spatstat] problem with a psp Line Segment Pattern when plotting and pointsOnlines performing

Michael Sumner mdsumner at gmail.com
Thu Sep 22 14:11:17 CEST 2011


It seems it is because one of your line segments is of length zero,
using your attachment:

load("track.RData")
library(spatstat)
which(!lengths.psp(track.psp) > 0)
[1] 17

Dropping the offender:

noZeroLengths <- track.psp[lengths.psp(track.psp) > 0]

(pts <- pointsOnLines(noZeroLengths, eps=50))
 planar point pattern: 1134 points
window: rectangle = [865841.7, 888666.8] x [6265115, 6300668] units

You might want to investigate why you have a zero length line segment
in your original shapefile, there's a lot of options for what you
might do in R but where you catch it depends on your main goals I
guess.

I think there are some good suggestions here for catching these cases
in spatstat and sp, but I haven't looked closely enough yet to say
anything helpful.

Cheers, Mike.

On Thu, Sep 22, 2011 at 9:00 PM, Mathieu Rajerison
<mathieu.rajerison at gmail.com> wrote:
> Thanks for the answer!
>
> I coerced my SpatialLinesDataFrame object to a psp object using a non-NA
> column.
>
> Plotting is OK but pointsOnLines still fails:
>
>> track.psp <- as(track[, 2], "psp")
>> plot(track.psp)
>> pts<-pointsOnLines(track.psp, eps=50)
> Erreur dans ppp(x = x, y = y, window = win) :
> all coordinate values are NA or NaN
>
> What's wrong?
>
> 2011/9/22 Michael Sumner <mdsumner at gmail.com>
>
>> The problem is that the first attribute on the track object, "ID" is
>> NA - and when plot.psp is trying to draw a legend it has nothing to
>> base the image "ribbon" on.
>>
>> This should avoid the error:
>>
>> plot(track.psp, ribbon = FALSE)
>>
>> Try subsetting the attributes in the coercion to psp, choose which
>> column you want from names(track) but note that with only one row the
>> ribbon legend will never be very interesting:
>>
>> track.psp <- as(track[,"PREC_PLANI"], "psp")
>>
>> plot(track.psp)
>>
>> Finally, do include sessionInfo() as requested - you have not let us
>> know that you require packages sp, rgdal, maptools, and spatstat - and
>> all of that is very important when determining what is going on.
>>
>> Cheers, Mike.
>>
>> On Thu, Sep 22, 2011 at 7:29 PM, Mathieu Rajerison
>> <mathieu.rajerison at gmail.com> wrote:
>> > Hi,
>> >
>> > I Have a problem with a psp object.
>> >
>> > I can't plot it, neither perform a pointsOnLines calculation on it.
>> >
>> > ---
>> > Here is what I obtain with my different operations:
>> >> track <- readOGR("voie.shp", "voie")
>> > OGR data source with driver: ESRI Shapefile
>> > Source: "voie.shp", layer: "voie"
>> > with 1 features and 14 fields
>> > Feature type: wkbLineString with 2 dimensions
>> >
>> >> track.psp <- as(track, "psp")
>> > Message d'avis :
>> > In as.psp.SpatialLinesDataFrame(from) : 13 columns of data frame
>> discarded
>> >
>> >> plot(track.psp)
>> > Erreur dans image.default(c(893999.767449278, 895777.422954333), c(Inf,
>> -Inf
>> > :
>> > 'x' and 'y' values must be finite and non-missing
>> >
>> > #plot(track) is OK
>> >
>> >> pts <- pointsOnLines(track.psp, eps=50)
>> > Erreur dans ppp(x = x, y = y, window = win) :
>> > all coordinate values are NA or NaN
>> > ---
>> >
>> > Any help would be appreciated.
>> >
>> > The related SpatialLinesDataFrame track object is attached to this mail
>> if
>> > you'd like to have a look..
>> >
>> > Thanks!
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > R-sig-Geo at 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 at gmail.com
>>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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 at gmail.com



More information about the R-sig-Geo mailing list