Subscribe to R-sig-geo feed
This is an archive for R-sig-geo, not a forum. It is not possible to post through Nabble - you may not start a new thread nor follow up an existing thread. If you wish to post, but are not subscribed to the list through the list homepage, subscribe first (through the list homepage, not via Nabble) and post from your subscribed email address. Until 2015-06-20, subscribers could post through Nabble, but policy has been changed as too many non-subscribers misunderstood the interface.
Updated: 2 hours 59 min ago

Re: Adding colour to polylines in Leaflet

Sat, 09/01/2018 - 09:36
Thank you Kent, that worked like a charm!
Regards

Dhiraj Khanna
Mob:09873263331


On Sat, Sep 1, 2018 at 7:59 PM Kent Johnson <[hidden email]> wrote:

> You have to include the points where the colors change in both polylines.
> Here is one way:
>
> x$lastColor = dplyr::lag(x$Color)
> map <-  leaflet(x)
> map <- addTiles(map)
> for( Color in
> levels(as.factor(x$Color))){
>   map <- addPolylines(map,lng=~lon,lat=~lat,data=x[x$Color==Color |
> x$lastColor==Color,], color=~Color) }
> map
>
> Kent
>
> On Sat, Sep 1, 2018 at 8:56 AM, Dhiraj Khanna <[hidden email]>
> wrote:
>
>> @Kent they are appearing as three separate lines. I am hoping to see them
>> joint with no gaps. The transition from row 4 to row 5 is where the speed
>> has changed from 2.1 knots to 3.4 knots. I am hoping to see another line
>> from row 4 to row 5 in red colour. Similarly for the other disjoint points.
>> Regards
>>
>> Dhiraj Khanna
>> Mob:09873263331
>>
>>
>> On Sat, Sep 1, 2018 at 6:17 PM Kent Johnson <[hidden email]> wrote:
>>
>>> Message: 5
>>>> Date: Sat, 1 Sep 2018 08:28:24 +0530
>>>> From: Dhiraj Khanna <[hidden email]>
>>>> To: [hidden email]
>>>> Subject: [R-sig-Geo] Adding colour to polylines in Leaflet
>>>> Message-ID:
>>>>         <
>>>> [hidden email]>
>>>> Content-Type: text/plain; charset="utf-8"
>>>>
>>>> I am working with shipping data where I get the dynamic parameters of a
>>>> ship like its position, speed, heading and rate of turn. I am then
>>>> trying
>>>> to plot this on a leaflet map and trying to colour the polylines based
>>>> on
>>>> the speed, but it always shows up in the same colour. Here’s some sample
>>>> data:
>>>>
>>>> <snip>
>>>> This is the code I have tried which doesn’t work:-
>>>>
>>>> map <-  leaflet(x) map <- addTiles(map) for( Color in
>>>> levels(as.factor(x$Color))){   map <- addPolylines(map,
>>>> lng=~lon,lat=~lat,data=x[x$Color==Color,], color=~Color) } map
>>>>
>>>> Regards
>>>> Dhiraj Khanna
>>>> Mob:09873263331
>>>
>>>
>>> What are you expecting to see? When I run your code I get a map with
>>> three lines, one red, one orange and one yellow.
>>>
>>> Kent
>>>
>>>
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Adding colour to polylines in Leaflet

Sat, 09/01/2018 - 09:29
You have to include the points where the colors change in both polylines.
Here is one way:

x$lastColor = dplyr::lag(x$Color)
map <-  leaflet(x)
map <- addTiles(map)
for( Color in
levels(as.factor(x$Color))){
  map <- addPolylines(map,lng=~lon,lat=~lat,data=x[x$Color==Color |
x$lastColor==Color,], color=~Color) }
map

Kent

On Sat, Sep 1, 2018 at 8:56 AM, Dhiraj Khanna <[hidden email]>
wrote:

> @Kent they are appearing as three separate lines. I am hoping to see them
> joint with no gaps. The transition from row 4 to row 5 is where the speed
> has changed from 2.1 knots to 3.4 knots. I am hoping to see another line
> from row 4 to row 5 in red colour. Similarly for the other disjoint points.
> Regards
>
> Dhiraj Khanna
> Mob:09873263331
>
>
> On Sat, Sep 1, 2018 at 6:17 PM Kent Johnson <[hidden email]> wrote:
>
>> Message: 5
>>> Date: Sat, 1 Sep 2018 08:28:24 +0530
>>> From: Dhiraj Khanna <[hidden email]>
>>> To: [hidden email]
>>> Subject: [R-sig-Geo] Adding colour to polylines in Leaflet
>>> Message-ID:
>>>         <CANHhK329-Y7hPJD9gSOs24mSqGkrjC481oQspNA
>>> [hidden email]>
>>> Content-Type: text/plain; charset="utf-8"
>>>
>>> I am working with shipping data where I get the dynamic parameters of a
>>> ship like its position, speed, heading and rate of turn. I am then trying
>>> to plot this on a leaflet map and trying to colour the polylines based on
>>> the speed, but it always shows up in the same colour. Here’s some sample
>>> data:
>>>
>>> <snip>
>>> This is the code I have tried which doesn’t work:-
>>>
>>> map <-  leaflet(x) map <- addTiles(map) for( Color in
>>> levels(as.factor(x$Color))){   map <- addPolylines(map,
>>> lng=~lon,lat=~lat,data=x[x$Color==Color,], color=~Color) } map
>>>
>>> Regards
>>> Dhiraj Khanna
>>> Mob:09873263331
>>
>>
>> What are you expecting to see? When I run your code I get a map with
>> three lines, one red, one orange and one yellow.
>>
>> Kent
>>
>>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Adding colour to polylines in Leaflet

Sat, 09/01/2018 - 07:56
@Kent they are appearing as three separate lines. I am hoping to see them
joint with no gaps. The transition from row 4 to row 5 is where the speed
has changed from 2.1 knots to 3.4 knots. I am hoping to see another line
from row 4 to row 5 in red colour. Similarly for the other disjoint points.
Regards

Dhiraj Khanna
Mob:09873263331


On Sat, Sep 1, 2018 at 6:17 PM Kent Johnson <[hidden email]> wrote:

> Message: 5
>> Date: Sat, 1 Sep 2018 08:28:24 +0530
>> From: Dhiraj Khanna <[hidden email]>
>> To: [hidden email]
>> Subject: [R-sig-Geo] Adding colour to polylines in Leaflet
>> Message-ID:
>>         <
>> [hidden email]>
>> Content-Type: text/plain; charset="utf-8"
>>
>> I am working with shipping data where I get the dynamic parameters of a
>> ship like its position, speed, heading and rate of turn. I am then trying
>> to plot this on a leaflet map and trying to colour the polylines based on
>> the speed, but it always shows up in the same colour. Here’s some sample
>> data:
>>
>> <snip>
>> This is the code I have tried which doesn’t work:-
>>
>> map <-  leaflet(x) map <- addTiles(map) for( Color in
>> levels(as.factor(x$Color))){   map <- addPolylines(map,
>> lng=~lon,lat=~lat,data=x[x$Color==Color,], color=~Color) } map
>>
>> Regards
>> Dhiraj Khanna
>> Mob:09873263331
>
>
> What are you expecting to see? When I run your code I get a map with three
> lines, one red, one orange and one yellow.
>
> Kent
>
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Adding colour to polylines in Leaflet

Sat, 09/01/2018 - 07:47
>
> Message: 5
> Date: Sat, 1 Sep 2018 08:28:24 +0530
> From: Dhiraj Khanna <[hidden email]>
> To: [hidden email]
> Subject: [R-sig-Geo] Adding colour to polylines in Leaflet
> Message-ID:
>         <CANHhK329-Y7hPJD9gSOs24mSqGkrjC481oQspNA
> [hidden email]>
> Content-Type: text/plain; charset="utf-8"
>
> I am working with shipping data where I get the dynamic parameters of a
> ship like its position, speed, heading and rate of turn. I am then trying
> to plot this on a leaflet map and trying to colour the polylines based on
> the speed, but it always shows up in the same colour. Here’s some sample
> data:
>
> <snip>
> This is the code I have tried which doesn’t work:-
>
> map <-  leaflet(x) map <- addTiles(map) for( Color in
> levels(as.factor(x$Color))){   map <- addPolylines(map,
> lng=~lon,lat=~lat,data=x[x$Color==Color,], color=~Color) } map
>
> Regards
> Dhiraj Khanna
> Mob:09873263331

What are you expecting to see? When I run your code I get a map with three
lines, one red, one orange and one yellow.

Kent

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Morans I

Sat, 09/01/2018 - 05:13
On Thu, 16 Aug 2018, Dechen Lham wrote:

> hi all,
>
> is the below the correct way to access spatial autocorrelation using
> morans I in a glm:
>
> #get coordinates first
> coords<-as.matrix(cbind(data$long,data$lat))
>
> #model
> m1 <- glm(response~ predictor1 + predictor 2+ predictor1*predictor2,
> + family=binomial, data=data)
>
> # Compute Moran's I using residuals of model
> lstw <- nb2listw((knn2nb(knearneigh(coords, k=1))))
>
> moran.test(residuals(m1), lstw)
No, certainly not correct; speculations suggest that using lm.morantest()
is less unsure, but I cannot find the reference at the moment. When
testing residuals from a linear model, the whole model output is needed
(see reference in ?lm.morantest) and this extends to glm models.

Roger

>
>
> Advise from experts using function moran.test will be much appreciated.
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: unbalanced panel

Sat, 09/01/2018 - 04:58
On Thu, 30 Aug 2018, Jérémie Juste wrote:

> Hello,
>
> I was wondering if there are any plans to allow the estimation of
> unbalanced panel in spdep or splm. I am not fortunate enough to have
> balanced spatial data and I think this woud be a valuable input to the
> community.

Could you please give us more motivation - are the missing observations
patterned? Which application area are you considering? What literature are
you using with regard to estimating unbalanced panels - is the problem
more temporal than spatial? Is this actually about interpolating or
imputing the missing values and the carrying through uncertainty? If this
was the case, then a Bayesian approach might be desirable, to permit the
imputation uncertainty to be carried through?

>
> Is there a way to compute direct and indirect effects when estimating an
> unbalanced panel spatial durbin model ?

First fit the model! Probably, unless you have a solid micro-model for why
global spillover is needed, you should keep the spatial process in the
error (local spillover), simplifying the impacts. In any case, avoiding
econometric fixed effects may let you use statistical random effects
models with (separable) temporal and spatial structure.

Roger

>
> Best regards,
> Jeremie Juste
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Adding colour to polylines in Leaflet

Fri, 08/31/2018 - 21:58
I am working with shipping data where I get the dynamic parameters of a
ship like its position, speed, heading and rate of turn. I am then trying
to plot this on a leaflet map and trying to colour the polylines based on
the speed, but it always shows up in the same colour. Here’s some sample
data:


structure(list(lat = c(51.88783, 51.8878441, 51.887825, 51.88659,
51.8866959, 51.8874931, 51.89359, 51.8941269, 51.8977051, 51.8994331,
51.90773, 51.91324, 51.91604, 51.9216652, 51.93353, 51.9419365 ), lon
= c(4.28763342, 4.287635, 4.28765154, 4.29007339, 4.29562664,
4.29917, 4.30641174, 4.30561829, 4.29263353, 4.284498, 4.261132,
4.24711847, 4.241075, 4.23262, 4.21523666, 4.1927), rateOfTurn = c(0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
sogKts = c(0, 0, 0, 2.1, 3.4, 4.6, 3.5, 3.8, 7.4, 7.9, 8.8,      9.1,
9.2, 9.2, 9.3, 9.3), cog = c(15, 15, 15, 122.2, 70.4,      70, 323.2,
315.3, 289.3, 290.9, 303.8, 303.7, 308.9, 324.5,      304.9, 301.4),
heading = c(163, 162, 163, 106, 71, 71, 303,      298, 289, 294, 303,
303, 310, 324, 304, 302), timestamp = c("2018-07-19T05:27:34",
"2018-07-19T05:39:35", "2018-07-19T05:45:34", "2018-07-19T05:57:37",
   "2018-07-19T06:02:48", "2018-07-19T06:04:49",
"2018-07-19T06:12:51",      "2018-07-19T06:13:32",
"2018-07-19T06:19:08", "2018-07-19T06:21:41",
"2018-07-19T06:28:42", "2018-07-19T06:32:50", "2018-07-19T06:34:37",
   "2018-07-19T06:37:41", "2018-07-19T06:43:49", "2018-07-19T06:50:09"
    ), Color = c("red", "red", "red", "red", "orange", "orange",
"orange", "orange", "orange", "orange", "yellow", "yellow",
"yellow", "yellow", "yellow", "yellow")), row.names = 32:47, class =
"data.frame")

This is the code I have tried which doesn’t work:-

map <-  leaflet(x) map <- addTiles(map) for( Color in
levels(as.factor(x$Color))){   map <- addPolylines(map,
lng=~lon,lat=~lat,data=x[x$Color==Color,], color=~Color) } map

Regards
Dhiraj Khanna
Mob:09873263331

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: A practical guide to geostatistical mapping

Fri, 08/31/2018 - 11:16
On Fri, 31 Aug 2018, Sarah Goslee wrote:

> Assuming you're looking for relevant R information, it seems like packages
> such as EGRET, dbhydroR, waterData, and RSAlgaeR are potentially relevant.
> My lab uses R extensively, including EGRET and in-house code.
>
> There's a lot of information out there, including case studies:
> Try a search for water quality on the incredibly useful rseek.org
>
> Most research uses the same data sources you bemoan - we sometimes have
> our own data, but largely rely on USGS etc.

Sarah,

   Thanks very much for the pointers!

   Good thing there's a long weekend coming: I have a lot of R reading to do
in addition to other put-off tasks. :-)

Best regards,

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: A practical guide to geostatistical mapping

Fri, 08/31/2018 - 11:12
Assuming you're looking for relevant R information, it seems like
packages such as EGRET, dbhydroR, waterData, and RSAlgaeR are
potentially relevant. My lab uses R extensively, including EGRET and
in-house code.

There's a lot of information out there, including case studies:

Try a search for water quality on the incredibly useful rseek.org

Most research uses the same data sources you bemoan - we sometimes
have our own data, but largely rely on USGS etc.

Sarah

On Fri, Aug 31, 2018 at 11:03 AM Rich Shepard <[hidden email]> wrote:
>
> On Fri, 31 Aug 2018, Rich Shepard wrote:
>
> > My work as an environmental science consultant, ... means that all data
> > available to me are generated by regulatory requirements, not by the needs
> > for a research project. And, the overwhelming number involve aquatic
> > chemistry (and biota such as fish) which adds the constant movement of the
> > medium into consideration.
>
>    I did two web searches this morning, one for 'aquatic geochemistry' the
> other for 'water quality geochemistry'. They both returned many hits on
> soils and ground waters, but only two related to surface waters.
>
>    There is a need to improve on this.
>
>    If anyone knows of documentation relevant to surface water quality,
> particularly flowing waters, please point me to them.
>
> Regards,
>
> Rich
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Sarah Goslee
http://www.functionaldiversity.org

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: A practical guide to geostatistical mapping

Fri, 08/31/2018 - 10:02
On Fri, 31 Aug 2018, Rich Shepard wrote:

> My work as an environmental science consultant, ... means that all data
> available to me are generated by regulatory requirements, not by the needs
> for a research project. And, the overwhelming number involve aquatic
> chemistry (and biota such as fish) which adds the constant movement of the
> medium into consideration.

   I did two web searches this morning, one for 'aquatic geochemistry' the
other for 'water quality geochemistry'. They both returned many hits on
soils and ground waters, but only two related to surface waters.

   There is a need to improve on this.

   If anyone knows of documentation relevant to surface water quality,
particularly flowing waters, please point me to them.

Regards,

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: A practical guide to geostatistical mapping

Fri, 08/31/2018 - 08:14
On Fri, 31 Aug 2018, Tomislav Hengl wrote:

> I am working on a rmarkdown update of the practical guide to GM (the
> working title is "A practical guide to spatial prediction with R"). As
> soon as I clean up these reports on my desk I will get on it (in about 2
> months should be online). My apologies to you and all other users for
> untidy website / my tardiness.

Tom,

   This is excellent news!

   I sent you a message yesterday at the e-mail address on the web site only
to have it bounce as 'user known in this domain.'

> In the meantime you might also find this useful:
> https://envirometrix.github.io/PredictiveSoilMapping/

   Thank you.

   I don't know if r-sig-geo is an appropriate forum for my questions that
are not specific to applying R packages, but to geostatistics themselves. If
not, I'd appreciate a pointer to a more appropriate place.

   One thing I've noticed in my readings about geostatistics is that (quite
appropriately) most are research oriented and written by academic
geostatisticians and ecologists. My work as an environmental science
consultant, an applied aqutic ecologist who left academia for the private
sector several decades ago, means that all data available to me are
generated by regulatory requirements, not by the needs for a research
project. And, the overwhelming number involve aquatic chemistry (and biota
such as fish) which adds the constant movement of the medium into
consideration.

   This makes it difficult for me to translate examples such as the Meuse
example in Chapter 5 to my projects. Currently I'm looking at mercury
concentrations in a river system and the sampling locations have an
intereesting pattern of clumps on the mainstem by major tributaries and are
otherwise quite dispersed. As a non-mathemtical statistician I've currently
no idea how to conduct exploratory analyses on such data. And, there's the
temporal aspct to be considered, too.

   I've much to learn because there's a real need for the application of
spatio-temporal statistics in regulatory environmental science instead of
the deterministic, differential equation models currently demanded by
regulators.

Best regards,

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: A practical guide to geostatistical mapping

Fri, 08/31/2018 - 02:43

Dear Rich,

I am working on a rmarkdown update of the practical guide to GM (the
working title is "A practical guide to spatial prediction with R"). As
soon as I clean up these reports on my desk I will get on it (in about 2
months should be online). My apologies to you and all other users for
untidy website / my tardiness.

In the meantime you might also find this useful:

https://envirometrix.github.io/PredictiveSoilMapping/

BR,

--
T. (Tom) Hengl
https://envirometrix.net/staff/tomislav-hengl


On 08/30/2018 10:43 PM, Rich Shepard wrote:
>    Received my printed copy of Tom Hengl's book yesterday. The web site has
> one page noting it was recently modified, but the most recent material I
> find there is from 2011. And some of the links on the data and R code tabs
> are broken.
>
>    Have there been additions or changes to the book since then? Is this
> still
> an active project?
>
>    I'm finding this a great addition to Goovaert's book which I read a long
> time ago and still reference.
>
> Rich
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

A practical guide to geostatistical mapping

Thu, 08/30/2018 - 15:43
   Received my printed copy of Tom Hengl's book yesterday. The web site has
one page noting it was recently modified, but the most recent material I
find there is from 2011. And some of the links on the data and R code tabs
are broken.

   Have there been additions or changes to the book since then? Is this still
an active project?

   I'm finding this a great addition to Goovaert's book which I read a long
time ago and still reference.

Rich

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

unbalanced panel

Thu, 08/30/2018 - 05:27
Hello,

I was wondering if there are any plans to allow the estimation of
unbalanced panel in spdep or splm. I am not fortunate enough to have
balanced spatial data and I think this woud be a valuable input to the
community.

Is there a way to compute direct and indirect effects when estimating an
unbalanced panel spatial durbin model ?

Best regards,
Jeremie Juste

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Spatial Query (Selection) with Apply

Wed, 08/29/2018 - 02:15
Hi Ariel,

Glad it helped.

Yes you could place your apply command into a lapply to get a list of
matrices.

Something like this should work:

dist_list <- lapply(tmp, function(coord) {

   apply(X = coord, MARGIN = 1, FUN = function(x) spDistsN1(coord, x,
longlat = T)

}

Robin



On Tue, Aug 28, 2018 at 9:13 PM, Ariel Fuentesdi <[hidden email]>
wrote:

> Thanks, Robin
>
> It worked perfectly, although I transformed the data from sf to
> SpatialDataFrame objects with:
>
> zones <- as(zones, "Spatial")
> nodes <- as(nodes, "Spatial")
>
> The next step I will follow is to create Distance Matrix like this:
>
> coord <- tmp2[[1]]@coords
> dist1 <- apply(X = coord, MARGIN = 1, FUN = function(x) spDistsN1(coord,
> x, longlat = T))
>
> obviously, the task is a distance matrix for every selection. ¿What would
> you recommend, the aggregate function as you talked before or something
> like a nested apply?
>
> Regards,
> Ariel
>
>
>
> 2018-08-27 19:32 GMT-03:00 Robin Lovelace <[hidden email]>:
>
>> Hi Ariel,
>>
>> It helps when asking for help with code to produce a reproducible
>> example. To understand your input data I've created nodes and zones based
>> on the spData data nz_height and nz_elev. Based on the assumption you want
>> to find all the nodes in each zone I think the direct answer to your
>> question is something like the following:
>>
>> tmp2 = lapply(s, function(x) {
>>   nodes[zones[x, ], ]
>> })
>>
>> The longer answer is that aggregate(), st_join() +
>> aggregate()/summarize() may provide quicker solutions, depending on what
>> you want to do with the points after grouping them by which zone they fall
>> in.
>> Note: I've used sf objects based on the explanation here
>> https://geocompr.robinlovelace.net/spatial-operations.html#spatial-vec
>> which may not work with sp data but the aggregate code should work roughly
>> the same:
>>
>> # install.packages("sf")
>> # install.packages("spData")
>> library(spData)
>> library(sf)
>> #> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
>> zones = nz
>> nodes = nz_height
>> tmp = list()
>> s = 1:nrow(nz)
>>
>> for(i in s) {
>>   tmp[[i]] = nodes[nz[i, ], ]
>> }
>>
>> # understand what's going on with plots (not shown)
>> # plot(st_geometry(nz))
>> # plot(st_geometry(tmp[[i]]), add = TRUE, col = "red")
>> # plot(nz[i, ], col = "green", add = TRUE)
>>
>> tmp2 = lapply(s, function(x) {
>>   nz_height[nz[x, ], ]
>> })
>>
>> identical(tmp, tmp2)
>> #> [1] TRUE
>>
>> Created on 2018-08-27 by the [reprex package](http://reprex.tidyverse.org)
>> (v0.2.0).
>>
>> I've also pasted the reprex into the geocompr github tracker so the plots
>> can be seen and the code formatted: https://github.com/Robinlovela
>> ce/geocompr/issues/294
>>
>> Hope this helps,
>>
>> Robin
>>
>>
>> On Mon, Aug 27, 2018 at 9:53 PM, Ariel Fuentesdi <
>> [hidden email]> wrote:
>>
>>> Hi,
>>>
>>> I want to do multiple selections of a point shapefile based on polygons
>>> on
>>> other layers, I can do this in a for loop, but I desire to do this in a
>>> function of the apply family.
>>>
>>> I named the point shapefile "nodes" and the polygons shapefile "zones".
>>>
>>> This is what I did:
>>>
>>> tmp <- list()
>>> for (i in 1:nrow(zones@data)) {
>>>     tmp[[i]] <- nodes[subset(zones, ESTUDIO == i),]
>>>     tmp
>>>   }
>>>
>>> But I have no clue how to change it to the apply family, can you provide
>>> an example of this?
>>>
>>> Thanks in advance.
>>>
>>> Regards,
>>> Ariel Fuentes
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email]
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

spatial-temporal variograms

Tue, 08/28/2018 - 16:45
Hello everyone!

Hope you are having a good day.

This is an opinion question, please:  Typically, we think of the separable
model for s/t variograms as not realistic.  Which ones are better, as a
rule, please?  I know the correct answer is "It depends".  But would we
consider metric, or sum-metric (or some of the others) more realistic,
please?

Thanks,
Erin


Erin Hodgess, PhD
mailto: [hidden email]

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Spatial Query (Selection) with Apply

Tue, 08/28/2018 - 15:13
Thanks, Robin

It worked perfectly, although I transformed the data from sf to
SpatialDataFrame objects with:

zones <- as(zones, "Spatial")
nodes <- as(nodes, "Spatial")

The next step I will follow is to create Distance Matrix like this:

coord <- tmp2[[1]]@coords
dist1 <- apply(X = coord, MARGIN = 1, FUN = function(x) spDistsN1(coord, x,
longlat = T))

obviously, the task is a distance matrix for every selection. ¿What would
you recommend, the aggregate function as you talked before or something
like a nested apply?

Regards,
Ariel



2018-08-27 19:32 GMT-03:00 Robin Lovelace <[hidden email]>:

> Hi Ariel,
>
> It helps when asking for help with code to produce a reproducible example.
> To understand your input data I've created nodes and zones based on the
> spData data nz_height and nz_elev. Based on the assumption you want to find
> all the nodes in each zone I think the direct answer to your question is
> something like the following:
>
> tmp2 = lapply(s, function(x) {
>   nodes[zones[x, ], ]
> })
>
> The longer answer is that aggregate(), st_join() + aggregate()/summarize()
> may provide quicker solutions, depending on what you want to do with the
> points after grouping them by which zone they fall in.
> Note: I've used sf objects based on the explanation here
> https://geocompr.robinlovelace.net/spatial-operations.html#spatial-vec
> which may not work with sp data but the aggregate code should work roughly
> the same:
>
> # install.packages("sf")
> # install.packages("spData")
> library(spData)
> library(sf)
> #> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
> zones = nz
> nodes = nz_height
> tmp = list()
> s = 1:nrow(nz)
>
> for(i in s) {
>   tmp[[i]] = nodes[nz[i, ], ]
> }
>
> # understand what's going on with plots (not shown)
> # plot(st_geometry(nz))
> # plot(st_geometry(tmp[[i]]), add = TRUE, col = "red")
> # plot(nz[i, ], col = "green", add = TRUE)
>
> tmp2 = lapply(s, function(x) {
>   nz_height[nz[x, ], ]
> })
>
> identical(tmp, tmp2)
> #> [1] TRUE
>
> Created on 2018-08-27 by the [reprex package](http://reprex.tidyverse.org)
> (v0.2.0).
>
> I've also pasted the reprex into the geocompr github tracker so the plots
> can be seen and the code formatted: https://github.com/Robinlovela
> ce/geocompr/issues/294
>
> Hope this helps,
>
> Robin
>
>
> On Mon, Aug 27, 2018 at 9:53 PM, Ariel Fuentesdi <[hidden email]
> > wrote:
>
>> Hi,
>>
>> I want to do multiple selections of a point shapefile based on polygons on
>> other layers, I can do this in a for loop, but I desire to do this in a
>> function of the apply family.
>>
>> I named the point shapefile "nodes" and the polygons shapefile "zones".
>>
>> This is what I did:
>>
>> tmp <- list()
>> for (i in 1:nrow(zones@data)) {
>>     tmp[[i]] <- nodes[subset(zones, ESTUDIO == i),]
>>     tmp
>>   }
>>
>> But I have no clue how to change it to the apply family, can you provide
>> an example of this?
>>
>> Thanks in advance.
>>
>> Regards,
>> Ariel Fuentes
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Spatial Query (Selection) with Apply

Mon, 08/27/2018 - 17:32
Hi Ariel,

It helps when asking for help with code to produce a reproducible example.
To understand your input data I've created nodes and zones based on the
spData data nz_height and nz_elev. Based on the assumption you want to find
all the nodes in each zone I think the direct answer to your question is
something like the following:

tmp2 = lapply(s, function(x) {
  nodes[zones[x, ], ]
})

The longer answer is that aggregate(), st_join() + aggregate()/summarize()
may provide quicker solutions, depending on what you want to do with the
points after grouping them by which zone they fall in.
Note: I've used sf objects based on the explanation here https://geocompr.
robinlovelace.net/spatial-operations.html#spatial-vec which may not work
with sp data but the aggregate code should work roughly the same:

# install.packages("sf")
# install.packages("spData")
library(spData)
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
zones = nz
nodes = nz_height
tmp = list()
s = 1:nrow(nz)

for(i in s) {
  tmp[[i]] = nodes[nz[i, ], ]
}

# understand what's going on with plots (not shown)
# plot(st_geometry(nz))
# plot(st_geometry(tmp[[i]]), add = TRUE, col = "red")
# plot(nz[i, ], col = "green", add = TRUE)

tmp2 = lapply(s, function(x) {
  nz_height[nz[x, ], ]
})

identical(tmp, tmp2)
#> [1] TRUE

Created on 2018-08-27 by the [reprex package](http://reprex.tidyverse.org)
(v0.2.0).

I've also pasted the reprex into the geocompr github tracker so the plots
can be seen and the code formatted: https://github.com/
Robinlovelace/geocompr/issues/294

Hope this helps,

Robin


On Mon, Aug 27, 2018 at 9:53 PM, Ariel Fuentesdi <[hidden email]>
wrote:

> Hi,
>
> I want to do multiple selections of a point shapefile based on polygons on
> other layers, I can do this in a for loop, but I desire to do this in a
> function of the apply family.
>
> I named the point shapefile "nodes" and the polygons shapefile "zones".
>
> This is what I did:
>
> tmp <- list()
> for (i in 1:nrow(zones@data)) {
>     tmp[[i]] <- nodes[subset(zones, ESTUDIO == i),]
>     tmp
>   }
>
> But I have no clue how to change it to the apply family, can you provide
> an example of this?
>
> Thanks in advance.
>
> Regards,
> Ariel Fuentes
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Spatial Query (Selection) with Apply

Mon, 08/27/2018 - 15:53
Hi,

I want to do multiple selections of a point shapefile based on polygons on
other layers, I can do this in a for loop, but I desire to do this in a
function of the apply family.

I named the point shapefile "nodes" and the polygons shapefile "zones".

This is what I did:

tmp <- list()
for (i in 1:nrow(zones@data)) {
    tmp[[i]] <- nodes[subset(zones, ESTUDIO == i),]
    tmp
  }

But I have no clue how to change it to the apply family, can you provide
an example of this?

Thanks in advance.

Regards,
Ariel Fuentes

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

How do I sample a synthetic random field at specified points?

Fri, 08/24/2018 - 15:50
Hail, all.

I have been able to generate a 3D synthetic random field (via unconditional
Gaussian simulation) using gstat package. I now need to sample the fields
at some specified coordinate points (not random points). I have not been
able to find a function to do this. Kindly note that my specified sample
points also come in 3D as I would need to sample at multiple depths for
each x-y coordinates.

Thank you, all.

Olatunde

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Pages