Re: [R-sig-Geo] Spatial join/intersection in R

2019-05-04 Thread Roozbeh Valavi
Thank you for your explanation, Tom.

Let me explain the case clearly.
The point layer is a very dense grid field collection across Great Britain.
I wanted to do spatial cross-validation by specifying each point in one of
the polygons (and assign a group of the polygons to a fold). Since the
points have been sampled on a regular grid they sometimes fall exactly on
the border of the polygons. If I use any sort of intersection or spatial
join, the points on the borders cause a problem.

Currently, I use st_jitter() in sf package give a bit of randomness to the
points. I wanted to see if there is another systematic way to avoid this.

Thanks,
Roozbeh

PhD Candidate
The Quantitative & Applied Ecology Group 
School of BioSciences | Faculty of Science
The University of Melbourne, VIC 3010, Australia
M: +61 423 283 238  E: rval...@student.unimelb.edu.au


On Wed, May 1, 2019 at 3:16 PM Tom Philippi  wrote:

> Roozbeh--
>
> What do you want to have happen with those points? Given the units in your
> figure, you could unambiguously assign them to the upper-right by adding a
> small value (0.01) to both the X and Y coordinates of your points.
> Whether that is a sensible thing to do depends on what your data are.
>
> How or why do the points fall exactly on your polygon boundaries?  What
> process puts them exactly on the polygon (grid cell) boundaries?  It
> appears your polygon boundaries are a grid at multiples of 0.05, although
> not all potential cells in a rectangle are shown.  Are there many other
> points not on polygon boundaries not shown in your figure, or are points
> only along grid lines?  If the latter, does it make sense to assign them to
> _polygons_ rather than line segments?
>
> If you're doing a sample draw or measuring locations with only a few
> decimal points of accuracy, and generating your polygon boundaries at exact
> multiples of 0.05, then it might make sense to shift all of your points +
> 1/10th of your point location resolution so that their coordinates never
> fall on polygon boundaries.  There _might_ be situations where instead of
> always adding (shifting up and right), you should randomly add or subtract
> in each direction for each point, but I'm stuck viewing this as points in
> sTomample units so I can't think of such a case.
>
> Tom
> .
>
> On Tue, Apr 30, 2019 at 7:18 PM Roozbeh Valavi <
> rval...@student.unimelb.edu.au> wrote:
>
>> Dear members,
>>
>> I want to do a spatial join/intersection in R. The problem is that some
>> of my points are lying exactly at the border of the adjacent polygons (see
>> the figure attached). So these points are either falling in both or none of
>> the polygons! Is there any way to avoid this?
>>
>> Thanks in advance.
>> Roozbeh
>>
>>
>> [image: image.png]
>>
>>
>>
>> --
>> *Roozbeh Valavi*
>> PhD Candidate
>> The Quantitative & Applied Ecology Group 
>> School of BioSciences | Faculty of Science
>> The University of Melbourne, VIC 3010, Australia
>> Mobile: +61 423 283 238
>> ___
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Question spdep package - lagsarlm not terminating

2019-05-04 Thread Raphael Mesaric via R-sig-Geo
Dear all,

I have a question with regards to the function „lagsarlm" from the package 
spdep. My problem is that the function is not terminating. Of course, I have 
quite a big grid (depending on the selection either 34000 or 60600 entries) and 
I also have a lot of explanatory variables (about 40). But I am still wondering 
whether there is something wrong. 

I tried to run a model based on the dataset „columbus“, and there I did not 
have any problems (but there are way fever entries and variables). I also 
compared the format of the required inputs, but everything seemed to be 
equivalent to the inputs used for the „columbus“ model.

Do you have any idea what might be the reason for the extremely long 
(respectively infinite, it has not terminated yet) computation time? Any 
suggestions are greatly appreciated.

If you would like to, I can also upload the corresponding code. However, the 
code includes some MAT-Files as I got the data in MATLAB. I do not yet attach 
them here because I read that attachments in another format than PDF are not 
desired as they may contain malicious software.

Thank you for your help in advance!

Best regards,

Raphael Mesaric
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] R-sig-Geo Digest, Vol 189, Issue 3

2019-05-04 Thread Maurizio Marchi
Thanks, I'll check it out.

Il giorno sab 4 mag 2019 alle 18:40 Edzer Pebesma <
edzer.pebe...@uni-muenster.de> ha scritto:

> The problem might be in the PROJ version; PROJ has seen a lot of
> development the last few years. I'm on
>
> Linking to GEOS 3.7.0, GDAL 2.4.0, PROJ 5.2.0
>
> Since you are on ubuntu, it should be pretty easy to get that too; see
> sf github pages for installing from ppa:ubuntugis-unstable:
> https://github.com/r-spatial/sf
>
> On 5/4/19 5:19 PM, Maurizio Marchi wrote:
> > Dear Prof.
> > Many thanks for your quick reply. Anyway I still have some differences
> > with your output, as well as some errors in the R console. Actually,
> > practically speaking, in my .png plot (attached) the origin of the axes
> > is still in Germany and the left and right borders of the image are
> > still rectilinear.
> >
> > *Here my R output using your code with the sessionInfo() at the end. I
> > hope it helps*
> >
> > R version 3.6.0 (2019-04-26) -- "Planting of a Tree" Copyright (C) 2019
> > The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu
> > (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You
> > are welcome to redistribute it under certain conditions. Type
> > 'license()' or 'licence()' for distribution details. Natural language
> > support but running in an English locale R is a collaborative project
> > with many contributors. Type 'contributors()' for more information and
> > 'citation()' on how to cite R or R packages in publications. Type
> > 'demo()' for some demos, 'help()' for on-line help, or 'help.start()'
> > for an HTML browser interface to help. Type 'q()' to quit R. > f =
> > 'tas_rcp85_land-rcm_eur_12km_01_mon_198012-208011.nc
> > ' >
> > library(stars) Loading required package: abind Loading required package:
> > sf Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3 > r = read_ncdf(f,
> > ncsub = cbind(start = c(1, 1, 1, 1), count = c(418, 406, 3, 1)),
> > eps=1e-3) > rx = read_stars(f, proxy = TRUE) # only for the crs! Warning
> > messages: 1: In CPL_read_gdal(as.character(x), as.character(options),
> > as.character(driver), : GDAL Message 1: The dataset has several
> > variables that could be identified as vector fields, but not all share
> > the same primary dimension. Consequently they will be ignored. 2: In
> > CPL_read_gdal(as.character(x), as.character(options),
> > as.character(driver), : GDAL Message 1: dimension #1 (time) is not a
> > Time dimension. 3: In CPL_read_gdal(as.character(x),
> > as.character(options), as.character(driver), : GDAL Message 1: dimension
> > #0 (ensemble_member) is not a Time dimension. > st_crs(r) = st_crs(rx) >
> > r0 = stars:::st_transform_proj.stars(r, 4326) > plot(r0[,,,1], border =
> > NA, axes = TRUE, reset = FALSE) Warning messages: 1: In
> > classInt::classIntervals(na.omit(values), min(nbreaks - 1, n.unq), : N
> > is large, and some styles will run very slowly; sampling imposed 2: In
> > st_is_longlat(x) : bounding box has potentially an invalid value range
> > for longlat data 3: In st_is_longlat(x) : bounding box has potentially
> > an invalid value range for longlat data 4: In st_is_longlat(x) :
> > bounding box has potentially an invalid value range for longlat data 5:
> > In st_is_longlat(x) : bounding box has potentially an invalid value
> > range for longlat data 6: In st_is_longlat(x) : bounding box has
> > potentially an invalid value range for longlat data >
> > library(rnaturalearth) > plot(ne_coastline(returnclass = "sf"), add =
> > TRUE, col = 'orange') Warning message: In
> > plot.sf(ne_coastline(returnclass = "sf"), add = TRUE, col = "orange") :
> > ignoring all but the first attribute > sessionInfo() R version 3.6.0
> > (2019-04-26) Platform: x86_64-pc-linux-gnu (64-bit) Running under:
> > Ubuntu 18.04.2 LTS Matrix products: default BLAS:
> > /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK:
> > /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1 locale: [1]
> > LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=it_IT.UTF-8
> > LC_COLLATE=en_GB.UTF-8 LC_MONETARY=it_IT.UTF-8 LC_MESSAGES=en_GB.UTF-8
> > [7] LC_PAPER=it_IT.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
> > LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C attached base packages:
> > [1] stats graphics grDevices utils datasets methods base other attached
> > packages: [1] rnaturalearth_0.1.0 stars_0.3-1 sf_0.7-4 abind_1.4-5
> > loaded via a namespace (and not attached): [1] Rcpp_1.0.1 magrittr_1.5
> > units_0.6-3 tidyselect_0.2.5 lattice_0.20-38 R6_2.4.0 rlang_0.3.4 [8]
> > rnaturalearthdata_0.2.0 dplyr_0.8.0.1 tools_3.6.0 parallel_3.6.0
> > grid_3.6.0 KernSmooth_2.23-15 ncmeta_0.0.4 [15] e1071_1.7-1 DBI_1.0.0
> > class_7.3-15 assertthat_0.2.1 tibble_2.1.1 RNetCDF_1.9-1 crayon_1.3.4
> > [22] tidyr_0.8.3 purrr_0.3.2 PCICt_0.5-4.1 glue_1.3.1 sp_1.3-1
> > compiler_3.6.0 pillar_1.3.1 [29] classInt_0.3-3 pkgconfig_2.0.2
> >
> >
> > --
> > Maurizio Marchi,
> > PhD Forest Scie

Re: [R-sig-Geo] R-sig-Geo Digest, Vol 189, Issue 3

2019-05-04 Thread Edzer Pebesma
The problem might be in the PROJ version; PROJ has seen a lot of
development the last few years. I'm on

Linking to GEOS 3.7.0, GDAL 2.4.0, PROJ 5.2.0

Since you are on ubuntu, it should be pretty easy to get that too; see
sf github pages for installing from ppa:ubuntugis-unstable:
https://github.com/r-spatial/sf

On 5/4/19 5:19 PM, Maurizio Marchi wrote:
> Dear Prof.
> Many thanks for your quick reply. Anyway I still have some differences
> with your output, as well as some errors in the R console. Actually,
> practically speaking, in my .png plot (attached) the origin of the axes
> is still in Germany and the left and right borders of the image are
> still rectilinear.
> 
> *Here my R output using your code with the sessionInfo() at the end. I
> hope it helps*
> 
> R version 3.6.0 (2019-04-26) -- "Planting of a Tree" Copyright (C) 2019
> The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu
> (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You
> are welcome to redistribute it under certain conditions. Type
> 'license()' or 'licence()' for distribution details. Natural language
> support but running in an English locale R is a collaborative project
> with many contributors. Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications. Type
> 'demo()' for some demos, 'help()' for on-line help, or 'help.start()'
> for an HTML browser interface to help. Type 'q()' to quit R. > f =
> 'tas_rcp85_land-rcm_eur_12km_01_mon_198012-208011.nc
> ' >
> library(stars) Loading required package: abind Loading required package:
> sf Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3 > r = read_ncdf(f,
> ncsub = cbind(start = c(1, 1, 1, 1), count = c(418, 406, 3, 1)),
> eps=1e-3) > rx = read_stars(f, proxy = TRUE) # only for the crs! Warning
> messages: 1: In CPL_read_gdal(as.character(x), as.character(options),
> as.character(driver), : GDAL Message 1: The dataset has several
> variables that could be identified as vector fields, but not all share
> the same primary dimension. Consequently they will be ignored. 2: In
> CPL_read_gdal(as.character(x), as.character(options),
> as.character(driver), : GDAL Message 1: dimension #1 (time) is not a
> Time dimension. 3: In CPL_read_gdal(as.character(x),
> as.character(options), as.character(driver), : GDAL Message 1: dimension
> #0 (ensemble_member) is not a Time dimension. > st_crs(r) = st_crs(rx) >
> r0 = stars:::st_transform_proj.stars(r, 4326) > plot(r0[,,,1], border =
> NA, axes = TRUE, reset = FALSE) Warning messages: 1: In
> classInt::classIntervals(na.omit(values), min(nbreaks - 1, n.unq), : N
> is large, and some styles will run very slowly; sampling imposed 2: In
> st_is_longlat(x) : bounding box has potentially an invalid value range
> for longlat data 3: In st_is_longlat(x) : bounding box has potentially
> an invalid value range for longlat data 4: In st_is_longlat(x) :
> bounding box has potentially an invalid value range for longlat data 5:
> In st_is_longlat(x) : bounding box has potentially an invalid value
> range for longlat data 6: In st_is_longlat(x) : bounding box has
> potentially an invalid value range for longlat data >
> library(rnaturalearth) > plot(ne_coastline(returnclass = "sf"), add =
> TRUE, col = 'orange') Warning message: In
> plot.sf(ne_coastline(returnclass = "sf"), add = TRUE, col = "orange") :
> ignoring all but the first attribute > sessionInfo() R version 3.6.0
> (2019-04-26) Platform: x86_64-pc-linux-gnu (64-bit) Running under:
> Ubuntu 18.04.2 LTS Matrix products: default BLAS:
> /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK:
> /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1 locale: [1]
> LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=it_IT.UTF-8
> LC_COLLATE=en_GB.UTF-8 LC_MONETARY=it_IT.UTF-8 LC_MESSAGES=en_GB.UTF-8
> [7] LC_PAPER=it_IT.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
> LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C attached base packages:
> [1] stats graphics grDevices utils datasets methods base other attached
> packages: [1] rnaturalearth_0.1.0 stars_0.3-1 sf_0.7-4 abind_1.4-5
> loaded via a namespace (and not attached): [1] Rcpp_1.0.1 magrittr_1.5
> units_0.6-3 tidyselect_0.2.5 lattice_0.20-38 R6_2.4.0 rlang_0.3.4 [8]
> rnaturalearthdata_0.2.0 dplyr_0.8.0.1 tools_3.6.0 parallel_3.6.0
> grid_3.6.0 KernSmooth_2.23-15 ncmeta_0.0.4 [15] e1071_1.7-1 DBI_1.0.0
> class_7.3-15 assertthat_0.2.1 tibble_2.1.1 RNetCDF_1.9-1 crayon_1.3.4
> [22] tidyr_0.8.3 purrr_0.3.2 PCICt_0.5-4.1 glue_1.3.1 sp_1.3-1
> compiler_3.6.0 pillar_1.3.1 [29] classInt_0.3-3 pkgconfig_2.0.2
> 
> 
> --
> Maurizio Marchi,
> PhD Forest Science - Ecological Mathematics
> Skype ID: maurizioxyz
> linux user 552742
> #EUFGIS national Focal point for Italy
> #Annals of Silvicultural Research Associated Editor
> https://scholar.google.it/citations?hl=en&user=_2X6fu8J
>