georuby 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/geo_ruby/shp4r/dbf.rb +9 -10
- data/lib/geo_ruby/shp4r/shp.rb +21 -26
- data/lib/geo_ruby/version.rb +1 -1
- data/spec/data/POLYGON.SHP +0 -0
- data/spec/geo_ruby/shp4r/shp_spec.rb +29 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dd38fae8554f897092835e5e185ec4739777764
|
4
|
+
data.tar.gz: 11a04ca5adb946903ce550758105658a7636f1dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32a42777bd969c252b1b47d852ab9d28442148b8b8f8f7275c56cd6114271310ee80a020f64190bd63d2c365587bf9e729c9db9a2d50ab9a464a0570d56a97a9
|
7
|
+
data.tar.gz: d386fd14dcacc221719441f9ff5bd896012d386fcd787a68567694a86068d77bddcd17b7b0ec4be4bafa4c08c46c28bf3a9658cfb04a143b5af2b3d3eb5cf1f5
|
data/README.md
CHANGED
@@ -59,6 +59,7 @@ Optional, require if you need the functionality:
|
|
59
59
|
require 'geo_ruby/georss' # GeoRSS
|
60
60
|
require 'geo_ruby/geojson' # GeoJSON
|
61
61
|
|
62
|
+
TODO: https://github.com/AnalyticalGraphicsInc/czml-writer
|
62
63
|
|
63
64
|
Use
|
64
65
|
===
|
@@ -108,7 +109,7 @@ the altitude data will not be output even if present. Envelopes output a LatLonA
|
|
108
109
|
For the output, the following geometric types are supported : Point, LineString, Polygon.
|
109
110
|
|
110
111
|
|
111
|
-
SHP reading
|
112
|
+
SHP reading and writing
|
112
113
|
---
|
113
114
|
|
114
115
|
Georuby has support for reading ESRI shapefiles (http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf).
|
@@ -221,4 +222,3 @@ can be sent to guilhem.vellut@gmail.com.
|
|
221
222
|
|
222
223
|
|
223
224
|
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/nofxx/georuby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
224
|
-
|
data/lib/geo_ruby/shp4r/dbf.rb
CHANGED
@@ -4,30 +4,29 @@ require 'rubygems'
|
|
4
4
|
begin
|
5
5
|
require 'dbf'
|
6
6
|
rescue LoadError
|
7
|
-
puts
|
8
|
-
puts
|
7
|
+
puts 'You\'ve loaded GeoRuby SHP Support.'
|
8
|
+
puts 'Please install the gem "dbf" to use it. `gem install dbf`'
|
9
9
|
end
|
10
10
|
|
11
11
|
module GeoRuby
|
12
12
|
# Ruby .shp files
|
13
13
|
module Shp4r
|
14
|
-
Dbf = DBF
|
15
14
|
|
16
|
-
module
|
15
|
+
module DBF
|
17
16
|
class Record
|
18
17
|
def [](v)
|
19
18
|
attributes[v]
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
class Field < Column::Base
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
22
|
+
# class Field < Column::Base
|
23
|
+
# def initialize(name, type, length, decimal = 0, version = 1, enc = nil)
|
24
|
+
# super(name, type, length, decimal, version, enc)
|
25
|
+
# end
|
26
|
+
# end
|
28
27
|
|
29
28
|
# Main DBF File Reader
|
30
|
-
class Reader < Table
|
29
|
+
class Reader < ::DBF::Table
|
31
30
|
alias_method :fields, :columns
|
32
31
|
def header_length
|
33
32
|
@columns_count
|
data/lib/geo_ruby/shp4r/shp.rb
CHANGED
@@ -35,11 +35,13 @@ module GeoRuby
|
|
35
35
|
# strip the shp out of the file if present
|
36
36
|
@file_root = file.gsub(/.shp$/i, '')
|
37
37
|
# check existence of shp, dbf and shx files
|
38
|
-
unless File.exist?(@file_root + '.shp') &&
|
38
|
+
unless File.exist?(@file_root + '.shp') &&
|
39
|
+
File.exist?(@file_root + '.dbf') &&
|
40
|
+
File.exist?(@file_root + '.shx')
|
39
41
|
fail MalformedShpException.new("Missing one of shp, dbf or shx for: #{@file}")
|
40
42
|
end
|
41
43
|
|
42
|
-
@dbf =
|
44
|
+
@dbf = DBF::Reader.open(@file_root + '.dbf')
|
43
45
|
@shx = File.open(@file_root + '.shx', 'rb')
|
44
46
|
@shp = File.open(@file_root + '.shp', 'rb')
|
45
47
|
read_index
|
@@ -65,7 +67,7 @@ module GeoRuby
|
|
65
67
|
end
|
66
68
|
|
67
69
|
# create a new Shapefile of the specified shp type (see ShpType) and
|
68
|
-
# with the attribute specified in the +fields+ array (see
|
70
|
+
# with the attribute specified in the +fields+ array (see DBF::Field).
|
69
71
|
# If a block is given, the ShpFile object newly created is passed to it.
|
70
72
|
def self.create(file, shp_type, fields, &proc)
|
71
73
|
file_root = file.gsub(/.shp$/i, '')
|
@@ -425,30 +427,23 @@ module GeoRuby
|
|
425
427
|
|
426
428
|
private
|
427
429
|
|
428
|
-
def
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
elsif geom.is_a? GeoRuby::SimpleFeatures::MultiLineString
|
438
|
-
'POLYLINE'
|
439
|
-
elsif geom.is_a? GeoRuby::SimpleFeatures::MultiPolygon
|
440
|
-
'POLYGON'
|
441
|
-
else
|
442
|
-
false
|
443
|
-
end
|
444
|
-
return false unless root
|
445
|
-
|
446
|
-
if geom.with_z
|
447
|
-
root = root + 'Z'
|
448
|
-
elsif geom.with_m
|
449
|
-
root = root + 'M'
|
430
|
+
def geom_type(geom)
|
431
|
+
case geom
|
432
|
+
when GeoRuby::SimpleFeatures::Point then 'POINT'
|
433
|
+
when GeoRuby::SimpleFeatures::LineString then 'POLYLINE'
|
434
|
+
when GeoRuby::SimpleFeatures::Polygon then 'POLYGON'
|
435
|
+
when GeoRuby::SimpleFeatures::MultiPoint then 'MULTIPOINT'
|
436
|
+
when GeoRuby::SimpleFeatures::MultiLineString then 'POLYLINE'
|
437
|
+
when GeoRuby::SimpleFeatures::MultiPolygon then 'POLYGON'
|
438
|
+
else false
|
450
439
|
end
|
451
|
-
|
440
|
+
end
|
441
|
+
|
442
|
+
def to_shp_type(geom)
|
443
|
+
return false unless klass = geom_type(geom)
|
444
|
+
klass += 'Z' if geom.with_z
|
445
|
+
klass += 'M' if geom.with_m
|
446
|
+
GeoRuby::Shp4r.const_get('ShpType::' + klass)
|
452
447
|
end
|
453
448
|
|
454
449
|
def commit_add(index)
|
data/lib/geo_ruby/version.rb
CHANGED
Binary file
|
@@ -51,7 +51,7 @@ describe GeoRuby::Shp4r do
|
|
51
51
|
it 'should parse fields' do
|
52
52
|
field = @shpfile.fields.first
|
53
53
|
expect(field.name).to eql('Chipoto')
|
54
|
-
# GeoRuby::Shp4r::
|
54
|
+
# GeoRuby::Shp4r::DBF now uses the decimal to choose between int and float
|
55
55
|
# So here is N instead of F
|
56
56
|
expect(field.type).to eql('N')
|
57
57
|
end
|
@@ -213,17 +213,24 @@ describe GeoRuby::Shp4r do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'test_creation' do
|
216
|
-
shpfile = GeoRuby::Shp4r::ShpFile.create(
|
216
|
+
shpfile = GeoRuby::Shp4r::ShpFile.create(
|
217
|
+
File.dirname(__FILE__) + '/../../data/point3.shp',
|
218
|
+
GeoRuby::Shp4r::ShpType::POINT,
|
219
|
+
[DBF::Column::Base.new('test', 'Hoyoyo', 'C', 10, 0)])
|
220
|
+
|
217
221
|
shpfile.transaction do |tr|
|
218
|
-
tr.add(GeoRuby::Shp4r::ShpRecord.new(
|
222
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(
|
223
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(123, 123.4),
|
224
|
+
'Hoyoyo' => 'HJHJJ'))
|
219
225
|
end
|
226
|
+
|
220
227
|
expect(shpfile.record_count).to eql(1)
|
221
228
|
shpfile.close
|
222
229
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/point3')
|
223
230
|
end
|
224
231
|
|
225
232
|
it 'test_creation_multipoint' do
|
226
|
-
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp', GeoRuby::Shp4r::ShpType::MULTIPOINT, [GeoRuby::Shp4r::
|
233
|
+
shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp', GeoRuby::Shp4r::ShpType::MULTIPOINT, [GeoRuby::Shp4r::DBF::Field.new('Hoyoyo', 'C', 10), GeoRuby::Shp4r::DBF::Field.new('Hello', 'N', 10)])
|
227
234
|
shpfile.transaction do |tr|
|
228
235
|
tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[123, 123.4], [345, 12.2]]), 'Hoyoyo' => 'HJHJJ', 'Hello' => 5))
|
229
236
|
end
|
@@ -232,6 +239,24 @@ describe GeoRuby::Shp4r do
|
|
232
239
|
rm_all_shp(File.dirname(__FILE__) + '/../../data/multipoint3')
|
233
240
|
end
|
234
241
|
|
242
|
+
it 'should work fine with upcase filenames' do
|
243
|
+
shpfile = GeoRuby::Shp4r::ShpFile.open(
|
244
|
+
File.dirname(__FILE__) + '/../../data/POLYGON.SHP')
|
245
|
+
|
246
|
+
shpfile.transaction do |tr|
|
247
|
+
expect(tr).to be_instance_of GeoRuby::Shp4r::ShpTransaction
|
248
|
+
tr.delete(0)
|
249
|
+
tr.add(GeoRuby::Shp4r::ShpRecord.new(
|
250
|
+
GeoRuby::SimpleFeatures::Polygon.from_coordinates(
|
251
|
+
[[[0, 0], [40, 0], [40, 40], [0, 40], [0, 0]],
|
252
|
+
[[10, 10], [10, 20], [20, 20], [10, 10]]]),
|
253
|
+
'Hello' => 'oook'))
|
254
|
+
end
|
255
|
+
|
256
|
+
expect(shpfile.record_count).to eql(1)
|
257
|
+
|
258
|
+
shpfile.close
|
259
|
+
end
|
235
260
|
end
|
236
261
|
|
237
262
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: georuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilhem Vellut
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: GeoRuby provides geometric data types from the OGC 'Simple Features'
|
17
17
|
specification.
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/geo_ruby/simple_features/polygon.rb
|
50
50
|
- lib/geo_ruby/version.rb
|
51
51
|
- lib/georuby.rb
|
52
|
+
- spec/data/POLYGON.SHP
|
52
53
|
- spec/data/geojson/feature.json
|
53
54
|
- spec/data/geojson/feature_collection.json
|
54
55
|
- spec/data/georss/atom.xml
|
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
version: '0'
|
115
116
|
requirements: []
|
116
117
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.4.
|
118
|
+
rubygems_version: 2.4.5
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Ruby data holder for OGC Simple Features
|