shapes 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require "shapes/version"
2
+ require 'shapes/shapeslib'
3
+ require 'shapes/shape_file'
4
+ require 'shapes/geometry'
5
+
6
+ module Shapes
7
+ end
@@ -0,0 +1,48 @@
1
+ module Shapes
2
+ class Point
3
+ attr_accessor :longitude, :latitude, :altitude, :projection
4
+
5
+ def initialize(lat = nil,long = nil,alt = nil,proj = :wgs84)
6
+ self.latitude = lat
7
+ self.longitude = long
8
+ self.altitude = alt
9
+ self.projection = proj
10
+ end
11
+ end
12
+
13
+ class Polygon
14
+ attr_accessor :vertices, :num_vertices
15
+
16
+ def initialize(vertices = nil,num_vertices = 4)
17
+ self.vertices = vertices if Array === vertices
18
+ self.vertices ||= []
19
+ self.num_vertices = num_vertices
20
+ end
21
+
22
+ def add_point(p)
23
+ self.vertices << p
24
+ end
25
+
26
+ def <<(p)
27
+ add_point p
28
+ end
29
+
30
+ def xs
31
+ self.vertices.map {|p| p.longitude }
32
+ end
33
+
34
+ def ys
35
+ self.vertices.map {|p| p.latitude }
36
+ end
37
+
38
+ def zs
39
+ self.vertices.map {|p| p.altitude }
40
+ end
41
+ end
42
+
43
+ class Arc < Polygon
44
+ end
45
+
46
+ class MultiPoint < Polygon
47
+ end
48
+ end
@@ -0,0 +1,63 @@
1
+ module Shapes
2
+ class ShapeFile
3
+ attr_accessor :handle
4
+
5
+ def initialize(afile = nil,stype = nil)
6
+ if afile and stype
7
+ self.handle = ShapesLib::create_shape afile, stype.to_s
8
+ elsif afile
9
+ self.handle = ShapesLib::open_shape afile
10
+ else
11
+ return self # get out of the function if no handle was passed
12
+ end
13
+
14
+ # but if we attempted to create a handle, make sure
15
+ # it actually returned something valid
16
+ return self.handle unless self.handle
17
+ end
18
+
19
+ def self.create(filename,shape_type,&block)
20
+ shape_handle = ShapesLib::create_shape filename, shape_type.to_s
21
+ return shape_handle unless shape_handle
22
+
23
+ inst = new
24
+ inst.handle = shape_handle
25
+
26
+ inst.define(&block)
27
+
28
+ ShapesLib::close_shape shape_handle
29
+ end
30
+
31
+ def self.open(filename,&block)
32
+ shape_handle = ShapesLib::open_shape filename
33
+ return shape_handle unless shape_handle
34
+
35
+ inst = new
36
+ inst.handle = shape_handle
37
+
38
+ inst.define(&block)
39
+
40
+ ShapesLib::close_shape shape_handle
41
+ end
42
+
43
+ def define(&block)
44
+ instance_eval(&block)
45
+ end
46
+
47
+ def point(p)
48
+ ShapesLib::create_object self.handle, 'point', 1, [p.longitude], [p.latitude], [p.altitude]
49
+ end
50
+
51
+ def polygon(p)
52
+ ShapesLib::create_object self.handle, 'polygon', p.num_vertices, p.xs, p.ys, p.zs
53
+ end
54
+
55
+ def arc(a)
56
+ ShapesLib::create_object self.handle, 'arc', a.num_vertices, a.xs, p.ys, p.zs
57
+ end
58
+
59
+ def multipoint(mp)
60
+ ShapesLib::create_object self.handle, 'multipoint', mp.num_vertices, mp.xs, mp.ys, mp.zs
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Shapes
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shapes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "shapes"
8
+ gem.version = Shapes::VERSION
9
+ gem.authors = ["Omar Qazi"]
10
+ gem.email = ["omar@predpol.com"]
11
+ gem.description = %q{A simple ruby library for writing shape files}
12
+ gem.summary = %q{Yeah, read the description}
13
+ gem.homepage = "http://www.predpol.com/"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.extensions = ['ext/shapes/extconf.rb']
20
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shapes
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Omar Qazi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple ruby library for writing shape files
15
+ email:
16
+ - omar@predpol.com
17
+ executables: []
18
+ extensions:
19
+ - ext/shapes/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - ext/shapes/Makefile
28
+ - ext/shapes/dbfopen.c
29
+ - ext/shapes/extconf.rb
30
+ - ext/shapes/libshp.a
31
+ - ext/shapes/mkmf.log
32
+ - ext/shapes/safileio.c
33
+ - ext/shapes/shapefil.h
34
+ - ext/shapes/shapes.c
35
+ - ext/shapes/shapes.h
36
+ - ext/shapes/shpopen.c
37
+ - ext/shapes/shptree.c
38
+ - lib/shapes.rb
39
+ - lib/shapes/geometry.rb
40
+ - lib/shapes/shape_file.rb
41
+ - lib/shapes/version.rb
42
+ - shapes.gemspec
43
+ homepage: http://www.predpol.com/
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.23
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Yeah, read the description
67
+ test_files: []