rgdal 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +16 -0
- data/lib/rgdal.rb +12 -0
- data/lib/rgdal/api.rb +31 -0
- data/lib/rgdal/base.rb +102 -0
- data/lib/rgdal/csv.rb +5 -0
- data/lib/rgdal/geojson.rb +5 -0
- data/lib/rgdal/kml.rb +5 -0
- data/lib/rgdal/overrides/data_source.rb +17 -0
- data/lib/rgdal/overrides/feature.rb +18 -0
- data/lib/rgdal/overrides/field_defn.rb +14 -0
- data/lib/rgdal/overrides/layer.rb +35 -0
- data/lib/rgdal/shp.rb +19 -0
- data/lib/rgdal/version.rb +3 -0
- data/rgdal.gemspec +22 -0
- data/spec/fixtures/record.yml +6 -0
- data/spec/integration/csv_spec.rb +28 -0
- data/spec/integration/geojson_spec.rb +20 -0
- data/spec/integration/kml_spec.rb +19 -0
- data/spec/integration/shp_spec.rb +19 -0
- data/spec/rgdal/overrides/data_source_spec.rb +19 -0
- data/spec/rgdal/overrides/feature_spec.rb +20 -0
- data/spec/rgdal/overrides/layer_spec.rb +26 -0
- data/spec/spec_helper.rb +14 -0
- metadata +147 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tyler Johnston
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# RGdal
|
2
|
+
|
3
|
+
Ruby wrapper for GDAL/OGR
|
4
|
+
|
5
|
+
### Terminology Reference:
|
6
|
+
|
7
|
+
| GDAL | Database |
|
8
|
+
| --------- | --------- |
|
9
|
+
| layer | table |
|
10
|
+
| field_def | column |
|
11
|
+
| feature | record |
|
12
|
+
| field | attribute |
|
13
|
+
|
14
|
+
## Examples
|
15
|
+
|
16
|
+
### Writing
|
17
|
+
> file = RGdal::SHP.new('tmp/tmpfolder')
|
18
|
+
> file.create_layer('filename')
|
19
|
+
> file.feature(lat, long, {attr: 'foo', bar: 'baz'})
|
20
|
+
> file.close
|
21
|
+
|
22
|
+
### Reading
|
23
|
+
> file = RGdal::SHP.new('tmp/tmpfolder')
|
24
|
+
> layer = file.current_layer
|
25
|
+
> layer.features.first.attributes
|
26
|
+
=> {attr: 'foo', bar: 'baz'}
|
27
|
+
> file.close
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
gem 'rgdal', git: 'git@github.com:spatialnetworks/RGdal.git'
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install rgdal
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake'
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
Bundler.setup
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
13
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :spec
|
data/lib/rgdal.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'gdal-ruby/ogr'
|
2
|
+
require 'rgdal/overrides/layer'
|
3
|
+
require 'rgdal/overrides/data_source'
|
4
|
+
require 'rgdal/overrides/field_defn'
|
5
|
+
require 'rgdal/overrides/feature'
|
6
|
+
require 'rgdal/api'
|
7
|
+
require 'rgdal/version'
|
8
|
+
require 'rgdal/base'
|
9
|
+
require 'rgdal/csv'
|
10
|
+
require 'rgdal/kml'
|
11
|
+
require 'rgdal/shp'
|
12
|
+
require 'rgdal/geojson'
|
data/lib/rgdal/api.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module RGdal
|
2
|
+
module API
|
3
|
+
module ClassMethods
|
4
|
+
def driver(name)
|
5
|
+
define_method :driver_name do
|
6
|
+
name
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def single_layer?(bool)
|
11
|
+
define_method(:single_layer?) { bool }
|
12
|
+
end
|
13
|
+
|
14
|
+
def reference(name)
|
15
|
+
define_method :reference do
|
16
|
+
name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def format(name)
|
21
|
+
define_method :format do
|
22
|
+
name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.included(receiver)
|
28
|
+
receiver.extend(ClassMethods)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rgdal/base.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
module RGdal
|
2
|
+
class Base
|
3
|
+
include API
|
4
|
+
|
5
|
+
attr_reader :data_source
|
6
|
+
attr_reader :current_layer
|
7
|
+
attr_reader :driver
|
8
|
+
|
9
|
+
reference nil
|
10
|
+
single_layer? false
|
11
|
+
format Gdal::Ogr::WKBUNKNOWN
|
12
|
+
|
13
|
+
def initialize(source)
|
14
|
+
@source = source
|
15
|
+
@data_source = driver.create_data_source(@source)
|
16
|
+
@current_layer = layers.first
|
17
|
+
@columns = @current_layer ? @current_layer.fields.map(&:name) : []
|
18
|
+
end
|
19
|
+
|
20
|
+
def layers
|
21
|
+
@layers = @data_source.layers
|
22
|
+
end
|
23
|
+
|
24
|
+
def driver
|
25
|
+
@driver ||= Gdal::Ogr.get_driver_by_name(driver_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def switch_layer(name)
|
29
|
+
@current_layer = @layers.select { |layer| layer.name == name }.first
|
30
|
+
@columns = @current_layer ? @current_layer.fields.map(&:name) : []
|
31
|
+
end
|
32
|
+
|
33
|
+
def new_layer(filename='export')
|
34
|
+
layer(filename).tap do |layer|
|
35
|
+
@current_layer = layer
|
36
|
+
@layers << layer
|
37
|
+
@columns = []
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def layer(filename)
|
42
|
+
@data_source.create_layer(filename, reference, format)
|
43
|
+
end
|
44
|
+
|
45
|
+
def close
|
46
|
+
@driver = nil
|
47
|
+
@data_source = nil
|
48
|
+
@current_layer = nil
|
49
|
+
@columns = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_column(name, options={})
|
53
|
+
options, name = {type: Gdal::Ogr::OFTSTRING, width: 254}.merge(options), header(name)
|
54
|
+
@columns.push(name)
|
55
|
+
field_definition = create_field_definition(name, options)
|
56
|
+
@current_layer.create_field(field_definition)
|
57
|
+
field_definition = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
alias_method :layer_field_definition, :add_column
|
61
|
+
|
62
|
+
def create_field_definition(name, options)
|
63
|
+
Gdal::Ogr::FieldDefn.new(name, options[:type]).tap do |field|
|
64
|
+
field.set_width(options[:width]) if options[:width]
|
65
|
+
field.set_precision(options[:precision]) if options[:precision]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def feature(longitude, latitude, attributes={})
|
70
|
+
feat = Gdal::Ogr::Feature.new(@current_layer.definition)
|
71
|
+
set_geometry(latitude, longitude, feat)
|
72
|
+
set_attributes(attributes, feat)
|
73
|
+
|
74
|
+
@current_layer.create_feature(feat)
|
75
|
+
@current_layer.reset_reading
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def header(key)
|
81
|
+
key
|
82
|
+
end
|
83
|
+
|
84
|
+
def value(attrib)
|
85
|
+
attrib
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_attributes(attributes, feat)
|
89
|
+
attributes.each do |key, value|
|
90
|
+
key = header(key)
|
91
|
+
feat.set_field(key, value(value)) if value.is_a?(String) && @columns.include?(key)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_geometry(latitude, longitude, feat)
|
96
|
+
coordinates = "POINT(#{longitude} #{latitude})"
|
97
|
+
geometry = Gdal::Ogr::create_geometry_from_wkt(coordinates)
|
98
|
+
feat.set_geometry(geometry)
|
99
|
+
geometry = nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/rgdal/csv.rb
ADDED
data/lib/rgdal/kml.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Gdal
|
2
|
+
module Ogr
|
3
|
+
class DataSource
|
4
|
+
def to_s
|
5
|
+
"<#Gdal::Ogr::DataSource name='#{get_name}' layer_count='#{get_layer_count}' driver='#{driver_name}'>"
|
6
|
+
end
|
7
|
+
|
8
|
+
def layers
|
9
|
+
get_layer_count.times.map { |i| get_layer(i) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def driver_name
|
13
|
+
get_driver.get_name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gdal
|
2
|
+
module Ogr
|
3
|
+
class Feature
|
4
|
+
def inspect
|
5
|
+
"#<Gdal::Ogr::Feature #{attributes.map { |k,v| "'#{k}'='#{v}'"}.join(' ')}>"
|
6
|
+
end
|
7
|
+
|
8
|
+
def attributes
|
9
|
+
{}.tap do |hash|
|
10
|
+
get_field_count.times do |i|
|
11
|
+
definition = self.get_field_defn_ref(i)
|
12
|
+
hash[definition.name] = get_field(i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Gdal
|
2
|
+
module Ogr
|
3
|
+
class FieldDefn
|
4
|
+
def to_s
|
5
|
+
"#<Gdal::Ogr::FieldDefn name='#{name}' type='#{type}' width='#{width}' precision='#{precision}' is_ignored='#{is_ignored}'>"
|
6
|
+
end
|
7
|
+
|
8
|
+
alias_method :name, :get_name
|
9
|
+
alias_method :type, :get_type_name
|
10
|
+
alias_method :width, :get_width
|
11
|
+
alias_method :precision, :get_precision
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Gdal
|
2
|
+
module Ogr
|
3
|
+
class Layer
|
4
|
+
|
5
|
+
alias_method :definition, :get_layer_defn
|
6
|
+
|
7
|
+
def features
|
8
|
+
[].tap do |array|
|
9
|
+
self.each { |feature| array << feature }
|
10
|
+
reset_reading
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#<Gdal::Ogr::Layer name='#{self.get_name}' field_count='#{fields.count}'>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def fields
|
19
|
+
definition.get_field_count.times.map { |i| definition.get_field_defn(i) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def column_names
|
23
|
+
fields.map(&:name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fields_hash
|
27
|
+
{}.tap do |hash|
|
28
|
+
fields.each do |field|
|
29
|
+
hash[field.name] = field.type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rgdal/shp.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module RGdal
|
2
|
+
class SHP < RGdal::Base
|
3
|
+
driver 'ESRI Shapefile'
|
4
|
+
format Gdal::Ogr::WKBPOINT
|
5
|
+
reference Gdal::Osr::SpatialReference.new.tap { |srs| srs.import_from_proj4("+proj=longlat +ellps=WGS84 +datum=WGS84") }
|
6
|
+
|
7
|
+
FILE_EXTENSIONS = ['.shp', '.dbf', '.prj', '.shx']
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def header(key)
|
12
|
+
key[0..9]
|
13
|
+
end
|
14
|
+
|
15
|
+
def value(attrib)
|
16
|
+
attrib[0..253]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/rgdal.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rgdal/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Spatial Networks"]
|
6
|
+
gem.email = ["sniadmin@spatialnetworks.com"]
|
7
|
+
gem.description = %q{Pretty wrapper for GDAL/OGR}
|
8
|
+
gem.summary = %q{Pretty wrapper for GDAL/OGR}
|
9
|
+
gem.homepage = "https://github.com/spatialnetworks/RGdal"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rgdal"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rgdal::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('gdal', '~> 0.0.5')
|
19
|
+
gem.add_dependency('activesupport')
|
20
|
+
gem.add_development_dependency('rspec')
|
21
|
+
gem.add_development_dependency('rake')
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGdal::CSV do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
6
|
+
@path = File.join(Dir.pwd, 'tmp', "#{SecureRandom.hex(16)}.csv")
|
7
|
+
@csv = RGdal::CSV.new(@path)
|
8
|
+
@csv.new_layer('test')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create a layer' do
|
12
|
+
@csv.current_layer.should_not == nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create field definition on the layer' do
|
16
|
+
@csv.layer_field_definition(@fixture.keys.first)
|
17
|
+
@csv.current_layer.fields.size.should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should create a valid CSV file' do
|
21
|
+
@fixture.keys.each { |key| @csv.add_column(key) }
|
22
|
+
@csv.feature(0.0, 0.0, @fixture)
|
23
|
+
@csv.close()
|
24
|
+
|
25
|
+
csv = CSV.open(@path, headers: true).first.to_hash
|
26
|
+
csv['city'].should == 'Washington'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGdal::GeoJSON do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
6
|
+
@path = File.join(Dir.pwd, 'tmp', "#{SecureRandom.hex(16)}.json")
|
7
|
+
@geojson = RGdal::GeoJSON.new(@path)
|
8
|
+
@geojson.new_layer('test')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create a valid CSV file' do
|
12
|
+
@fixture.keys.each { |key| @geojson.add_column(key) }
|
13
|
+
@geojson.feature(0.0, 0.0, @fixture)
|
14
|
+
@geojson.close()
|
15
|
+
GC.start && sleep(5) # Sigh
|
16
|
+
|
17
|
+
geojson = JSON.parse(File.read(@path))
|
18
|
+
geojson['features'].length.should == 1
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGdal::KML do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
6
|
+
@path = File.join(Dir.pwd, 'tmp', "#{SecureRandom.hex(16)}")
|
7
|
+
@kml = RGdal::KML.new(@path)
|
8
|
+
@kml.new_layer('test')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create a KML file' do
|
12
|
+
@fixture.keys.each { |key| @kml.add_column(key) }
|
13
|
+
@kml.feature(0.0, 0.0, @fixture)
|
14
|
+
@kml.close()
|
15
|
+
GC.start && sleep(5) # Sigh
|
16
|
+
|
17
|
+
File.open(@path).readline.should == "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGdal::SHP do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
6
|
+
@path = File.join(Dir.pwd, 'tmp', "#{SecureRandom.hex(16)}")
|
7
|
+
Dir.mkdir(@path)
|
8
|
+
@shp = RGdal::SHP.new(@path)
|
9
|
+
@shp.new_layer('test')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should create a shapefile' do
|
13
|
+
@fixture.keys.each { |key| @shp.add_column(key) }
|
14
|
+
@shp.feature(0.0, 0.0, @fixture)
|
15
|
+
@shp.close()
|
16
|
+
|
17
|
+
File.size(File.join(@path, 'test.dbf')).should_not == 0
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gdal::Ogr::DataSource do
|
4
|
+
before(:each) do
|
5
|
+
@path = "tmp/#{SecureRandom.hex(16)}.csv"
|
6
|
+
@csv = RGdal::CSV.new(@path)
|
7
|
+
@csv.new_layer('test')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return an array of layer objects' do
|
11
|
+
@csv.data_source.layers.length.should == 1
|
12
|
+
@csv.new_layer('foobar')
|
13
|
+
@csv.data_source.layers.length.should == 2
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have a driver name' do
|
17
|
+
@csv.driver_name.should == 'CSV'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gdal::Ogr::Feature do
|
4
|
+
before(:each) do
|
5
|
+
@path = File.join(Dir.pwd, "tmp/#{SecureRandom.hex(16)}.csv")
|
6
|
+
@csv = RGdal::CSV.new(@path)
|
7
|
+
@csv.new_layer('test')
|
8
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create a hash of the feature' do
|
12
|
+
@csv.new_layer('test')
|
13
|
+
@fixture.keys.each { |k| @csv.layer_field_definition(k) }
|
14
|
+
@csv.feature('0.0', '0.0', @fixture)
|
15
|
+
|
16
|
+
attributes = @csv.current_layer.get_next_feature.attributes
|
17
|
+
attributes.class.should eq(Hash)
|
18
|
+
attributes['city'].should == 'Washington'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gdal::Ogr::Layer do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = YAML.load(File.read('spec/fixtures/record.yml'))['example_one']
|
6
|
+
@path = File.join(Dir.pwd, 'tmp', "#{SecureRandom.hex(16)}.csv")
|
7
|
+
@csv = RGdal::CSV.new(@path)
|
8
|
+
@csv.new_layer('test')
|
9
|
+
@fixture.keys.each { |k| @csv.layer_field_definition(k) }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return an array of column names' do
|
13
|
+
@csv.current_layer.column_names.should == %w(latitude longitude city state misc)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return an array of features' do
|
17
|
+
@csv.feature('0.0', '0.0', @fixture)
|
18
|
+
@csv.current_layer.features.length.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return a field hash with types' do
|
22
|
+
hash = @csv.current_layer.fields_hash
|
23
|
+
hash.keys.should == %w(latitude longitude city state misc)
|
24
|
+
hash.values.should == %w(String) * 5
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rgdal'
|
3
|
+
require 'csv'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'json'
|
6
|
+
require 'securerandom'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.after(:each) do
|
11
|
+
temp_directory = File.join(Dir.pwd, 'tmp')
|
12
|
+
FileUtils.rm_r(Dir["#{temp_directory}/[^.]*"])
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rgdal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Spatial Networks
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: gdal
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Pretty wrapper for GDAL/OGR
|
79
|
+
email:
|
80
|
+
- sniadmin@spatialnetworks.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/rgdal.rb
|
92
|
+
- lib/rgdal/api.rb
|
93
|
+
- lib/rgdal/base.rb
|
94
|
+
- lib/rgdal/csv.rb
|
95
|
+
- lib/rgdal/geojson.rb
|
96
|
+
- lib/rgdal/kml.rb
|
97
|
+
- lib/rgdal/overrides/data_source.rb
|
98
|
+
- lib/rgdal/overrides/feature.rb
|
99
|
+
- lib/rgdal/overrides/field_defn.rb
|
100
|
+
- lib/rgdal/overrides/layer.rb
|
101
|
+
- lib/rgdal/shp.rb
|
102
|
+
- lib/rgdal/version.rb
|
103
|
+
- rgdal.gemspec
|
104
|
+
- spec/fixtures/record.yml
|
105
|
+
- spec/integration/csv_spec.rb
|
106
|
+
- spec/integration/geojson_spec.rb
|
107
|
+
- spec/integration/kml_spec.rb
|
108
|
+
- spec/integration/shp_spec.rb
|
109
|
+
- spec/rgdal/overrides/data_source_spec.rb
|
110
|
+
- spec/rgdal/overrides/feature_spec.rb
|
111
|
+
- spec/rgdal/overrides/layer_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: https://github.com/spatialnetworks/RGdal
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.24
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Pretty wrapper for GDAL/OGR
|
137
|
+
test_files:
|
138
|
+
- spec/fixtures/record.yml
|
139
|
+
- spec/integration/csv_spec.rb
|
140
|
+
- spec/integration/geojson_spec.rb
|
141
|
+
- spec/integration/kml_spec.rb
|
142
|
+
- spec/integration/shp_spec.rb
|
143
|
+
- spec/rgdal/overrides/data_source_spec.rb
|
144
|
+
- spec/rgdal/overrides/feature_spec.rb
|
145
|
+
- spec/rgdal/overrides/layer_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
has_rdoc:
|