Search code examples
ruby-on-railsrubyrgeo

Why do I get "Errno::ENOENT: No such file or directory" when joining a filename?


I have a file I'm trying to open in a Rails application. For some reason Ruby is splitting the name of the file.

For example:

root = Rails.root
path = root.join('lib/tasks/filename.shp')
puts path

What is output is /lib/tasks/filename/shp.

Then I run the command:

factory = Region::GEOFACTORY
RGeo::Shapefile::Reader.open(path, :factory => factory) do |file|

I get the error message:

Errno::ENOENT: No such file or directory - /lib/tasks/filename/.shp

It looks like the file has been split into filename and .shp?


Solution

  • Try

    path = File.join(Rails.root, 'lib/tasks/filename.shp')
    factory = Region::GEOFACTORY
    RGeo::Shapefile::Reader.open(path, :factory => factory)