Closed carbz closed 10 years ago
As an alternative, Zaiming and I find this works well:
network_shp <- readShapeLines(paste0(base_dir,'/networks-proposed.shp'), proj4string = CRS(as.character(proj4string)))
OK. But we can't just assume the CRS is the same as the metrics-local csv. It doesn't look like NP guarantees that they're the same when output (the default targetProj4 for transform is latlon and when saving the network this is NOT overridden. (and beside, it's just bad to assume they're the same)
So, we'll need to find the CRS from the shp some other way (readOGR determined it implicitly)
Problem seems to be systemic on Unix platforms. I'm continually gettng an "Error in ogrInfo(..." message even on the test data set. But it does works fine on Windows.
> np <- read_networkplan(base_dir)
OGR data source with driver: ESRI Shapefile
Source: "C:/Users/carbatron/Documents/2974", layer: "networks-proposed"
with 107 features and 1 fields
Feature type: wkbLineString with 2 dimensions
list()
It works fine with my computer and my virtual windows machine. I'm not sure if this is a platform specific issue for system setting related issue. Can you find another Apple machine and see if it works?
Naichen tested the library today and it works fine on his machine. So it's just confined to my personal Mac OS instance. So basically I need to look into my own system settings and library should in theory work fine... Thanks for the research.
I keep on getting the following error message:
np <- read_networkplan(base_dir)
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) :
Cannot open file
Even though it's isolated to my personal machine, it may come up in the future with others so I'll try to document my eventual fix for this problem.
What version of rgdal do you have? See https://stat.ethz.ch/pipermail/r-sig-geo/2013-January/017298.html (just googled your error).
In general, maybe worth comparing your sessionInfo() to a machine where there is no issue, and making sure the problem isn't with a dependent package version. If it turns out to be a dependency version issue, note that the R package DESCRIPTION file allows you to specify version numbers in the dependencies (eg. thishttps://github.com/SEL-Columbia/formhub.R/blob/master/DESCRIPTION#L9), which will allow future-proofing.
On Tue, Apr 15, 2014 at 6:16 PM, Jonathan Carbajal <notifications@github.com
wrote:
I keep on getting the following error message: np <- read_networkplan(base_dir) Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : Cannot open file
Even though it's isolated to my personal machine, it may come up in the future with others so I'll try to document my eventual fix for this problem.
Reply to this email directly or view it on GitHubhttps://github.com/SEL-Columbia/networkplanner.R/issues/36#issuecomment-40541317 .
Prabhas Pokharel http://prabhasp.com US mobile: +1 347 948 7654 twitter/skype/facebook/whatever: prabhasp
Rgdal is Version 0.8-16 which is greater than 0.8-4 so that shouldn't be my bug...
That is a great version control tip and will keep that ability to specify package version in mind for future development.
Comparing the sessionInfo() outputs seems like a good avenue to explore though since I was stuck before. I'm noticing that my rgeos & maptools versions are predated in the bad version. I'll try updating those first...
Good Session (via my virtual Windows 7 environment)
np <- read_networkplan(base_dir) OGR data source with driver: ESRI Shapefile Source: "C:/Users/carbatron/Downloads/SULA-NP-Output-2940", layer: "networks-proposed" with 102 features and 1 fields Feature type: wkbLineString with 2 dimensions list()
sessionInfo() R version 3.0.3 (2014-03-06) Platform: x86_64-w64-mingw32/x64 (64-bit)
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] networkplanner_0.0.1 R.utils_1.29.8 R.oo_1.18.0
[4] R.methodsS3_1.6.1 geosphere_1.3-8 abind_1.4-0
[7] rgeos_0.3-4 rgdal_0.8-16 maptools_0.8-29
[10] sp_1.0-14 lubridate_1.3.3 RCurl_1.95-4.1
[13] bitops_1.0-6 plyr_1.8.1 stringr_0.6.2
[16] igraph_0.7.0
loaded via a namespace (and not attached): [1] digest_0.6.4 foreign_0.8-59 grid_3.0.3 lattice_0.20-27 [5] memoise_0.1 Rcpp_0.11.1 tools_3.0.3
Bad Session (via my Mac OS)
np <- read_networkplan(base_dir) Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : Cannot open file
sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] networkplanner_0.0.1 R.utils_1.29.8 R.oo_1.18.0 R.methodsS3_1.6.1 geosphere_1.3-8
[6] abind_1.4-0 rgeos_0.3-3 rgdal_0.8-16 maptools_0.8-27 sp_1.0-14
[11] lubridate_1.3.3 RCurl_1.95-4.1 bitops_1.0-6 plyr_1.8 stringr_0.6.2
[16] igraph_0.7.0
loaded via a namespace (and not attached): [1] digest_0.6.4 foreign_0.8-55 grid_3.0.2 lattice_0.20-23 memoise_0.1 tools_3.0.2
The issue came down to syntax(!) when defining the base_directory. Very elemental mistake and this doesn't come down to anything wrong with readOGR.
Defining the base directory as such works:
For a PC envirorment
base_dir <- "C:/Users/carbatron/Documents/2974" np <- read_networkplan(base_dir) OGR data source with driver: ESRI Shapefile ...
For a Mac envirorment
base_dir <- "Dropbox/Myanmar_GIS/Modeling/Tests/680/" test_np <- read_networkplan(base_dir) OGR data source with driver: ESRI Shapefile ...
While this is a bad way to define the directory:
base_dir <- "~/Dropbox/Myanmar_GIS/Modeling/Tests/680" test_np <- read_networkplan(base_dir) Error in file(file, "rt") : cannot open the connection...
R should know how to expand the home directory, let me look into this now.
On Wed, Apr 16, 2014 at 12:17 PM, Jonathan Carbajal < notifications@github.com> wrote:
The issue came down to syntax(!) when defining the bade_directory. Very elemental mistake and this doesn't come down to anything wrong with readOGR.
Defining the base directory as such works:
For a PC envirorment
base_dir <- "C:/Users/carbatron/Documents/2974" np <- read_networkplan(base_dir) OGR data source with driver: ESRI Shapefile ...
For a Mac envirorment
base_dir <- "Dropbox/Myanmar_GIS/Modeling/Tests/680/" test_np <- read_networkplan(base_dir) OGR data source with driver: ESRI Shapefile ...
While this is a bad way to define the directory:
base_dir <- "~/Dropbox/Myanmar_GIS/Modeling/Tests/680" test_np <- read_networkplan(base_dir) Error in file(file, "rt") : cannot open the connection...
— Reply to this email directly or view it on GitHubhttps://github.com/SEL-Columbia/networkplanner.R/issues/36#issuecomment-40619390 .
require(devtools) install_github('networkplanner.R', 'SEL-Columbia', ref="read_np_file_bug") require(networkplanner)
directory_name <- "~/work/r/networkplanner.R/inst/test_data//108/" test_np <- read_networkplan(directory_name)
Please run the preceeding code and change directory_name to whatever crazy file path you can imagine to test if my bug fix works.
I tested on my Ubuntu and windows vritual machine they all work fine on my side.
Great, it works now! Thanks for the fix.
install_github('networkplanner.R', 'SEL-Columbia', ref="read_np_file_bug") require(networkplanner) base_dir <- "~/Dropbox/Myanmar_GIS/Modeling/Tests/680" np <- read_networkplan(base_dir)
OGR data source with driver: ESRI Shapefile Source: "/Users/carbz/Dropbox/Myanmar_GIS/Modeling/Tests/680", layer: "networks-proposed" with 3406 features and 1 fields Feature type: wkbLineString with 2 dimensions list()
no problem ;)
I'm going to merge with master, and close this issue then.
On Wed, Apr 16, 2014 at 2:53 PM, Jonathan Carbajal <notifications@github.com
wrote:
Great, it works now! Thanks for the fix.
install_github('networkplanner.R', 'SEL-Columbia', ref="read_np_file_bug") require(networkplanner) base_dir <- "~/Dropbox/Myanmar_GIS/Modeling/Tests/680" np <- read_networkplan(base_dir)
OGR data source with driver: ESRI Shapefile Source: "/Users/carbz/Dropbox/Myanmar_GIS/Modeling/Tests/680", layer: "networks-proposed" with 3406 features and 1 fields
Feature type: wkbLineString with 2 dimensions list()
—
Reply to this email directly or view it on GitHubhttps://github.com/SEL-Columbia/networkplanner.R/issues/36#issuecomment-40637462 .
Sometimes,
read_networkplan
fails due to thereadOGR
on Line 117.Below is an example error message when trying to execute the read_networkplan.
np <- read_networkplan(base_dir) Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : Cannot open file
I would recommend reverting back to maptools'
readShapeLines
in lieu and perhaps specifying the projection read via the metrics local file. Or perhaps there is a way around the readOGR issue?