ropensci / tiler

Generate geographic and non-geographic map tiles from R
https://docs.ropensci.org/tiler
Other
64 stars 8 forks source link

Finding OSGeo4w resources #7

Closed NHPatterson closed 6 years ago

NHPatterson commented 6 years ago

Hello,

I installed tiler on my windows 10 desktop and following the instructions outlined in the introduction, including installing 64-bit OSGeo4W from https://trac.osgeo.org/osgeo4w/. No problems there, however, the default installation went directly to C:/OSGeo4W64 and thus there is no C:/Program Files/QGIS 3.0/OSGeo4W.bat. This file is found at C:/OSGeo4W64/OSGeo4W.bat. When I use tiler_options(osgeo4w = 'C:/OSGeo4W64/OSGeo4W.bat'), I have no issues tiling images, however, I have to set this in each R session, even after adding the .bat file to my path.

Any suggestions?

NHPatterson commented 6 years ago

Here is some verbose code that searches the system path for the OSGeo4W and the associated .bat file and adds them to tiler_options()..

#get system PATH variables as list
sys_path_vars <- Sys.getenv(x = "PATH", unset = "", names = NA)
sys_path_vars <- strsplit(sys_path_vars, ';')

#search for OsGeo4W.bat and add to tiler options if found
osgeo4w <- sys_path_vars[grepl('OSGeo4W.bat',sys_path_vars)]

if(length(osgeo4w) > 0){

  osgeo4w <- gsub("\\\\", "/", osgeo4w)
  if(file.exists(osgeo4w)) tiler_options(osgeo4w = osgeo4w)

}else{
  #search for OsGeo4W folder, reformat path slashes
  osgeo4w <- sys_path_vars[grepl('OSGeo4W',sys_path_vars)]
  osgeo4w <- gsub("\\\\", "/", osgeo4w)

  #determine if end of line is windows format
  end_sep <- substr(osgeo4w, nchar(osgeo4w), nchar(osgeo4w))

  #construct string to OSGeo4w.bat
  if(end_sep == '/'){
    osgeo4w <- paste0(osgeo4w, 'OSGeo4w.bat')
  }else{
    osgeo4w <- file.path(osgeo4w, 'OSGeo4w.bat')
  }

  #add to tiler_options..
  if(file.exists(osgeo4w)) tiler_options(osgeo4w = osgeo4w)
}
leonawicz commented 6 years ago

Hi, thanks for submitting this issue.

I'm found a small bug related to the system path on Windows being ignored, hence why you had to specify it in tiler options every R session even with the path to the OSGeo4W64 directory being on your system path.

I should have an updated dev version pushed to GitHub in the next day or two that fixes this issue. This is a significant enough fix that I'll follow with a CRAN update (after more robust package checks).

Side note: I'm also going to roll back the flexibility I tried to put in place initially when I decided to have R poke around looking for OSGeo4W.bat. In hindsight I think this was bad practice on my part. I've decided to stick to the standard approach of "1. Install system requirement. 2. Add it to your system path so R can find it." and not do any searching for an installed program. This keeps it simple, standard and not open ended or confusing. I'll simplify the documentation to reflect this.

Thanks! :) Matt

leonawicz commented 6 years ago

Install the development version 0.2.1 from GitHub and it should now work with the path to the directory containing the .bat file on your system path. The issue was not that tile couldn't find the directory on the system path, but that it was failing to append it with the .bat filename for the system call.

I plan to submit to CRAN soon. I'll mark this closed. Thanks again.