jsl-GeoRuby 1.3.3
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/MIT-LICENSE +7 -0
- data/README +83 -0
- data/georuby.gemspec +37 -0
- data/lib/geo_ruby.rb +16 -0
- data/lib/geo_ruby/shp4r/dbf.rb +180 -0
- data/lib/geo_ruby/shp4r/shp.rb +701 -0
- data/lib/geo_ruby/simple_features/envelope.rb +134 -0
- data/lib/geo_ruby/simple_features/ewkb_parser.rb +216 -0
- data/lib/geo_ruby/simple_features/ewkt_parser.rb +336 -0
- data/lib/geo_ruby/simple_features/geometry.rb +225 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +136 -0
- data/lib/geo_ruby/simple_features/geometry_factory.rb +81 -0
- data/lib/geo_ruby/simple_features/georss_parser.rb +135 -0
- data/lib/geo_ruby/simple_features/helper.rb +18 -0
- data/lib/geo_ruby/simple_features/line_string.rb +166 -0
- data/lib/geo_ruby/simple_features/linear_ring.rb +12 -0
- data/lib/geo_ruby/simple_features/multi_line_string.rb +39 -0
- data/lib/geo_ruby/simple_features/multi_point.rb +41 -0
- data/lib/geo_ruby/simple_features/multi_polygon.rb +38 -0
- data/lib/geo_ruby/simple_features/point.rb +236 -0
- data/lib/geo_ruby/simple_features/polygon.rb +150 -0
- data/rakefile.rb +44 -0
- data/test/data/multipoint.dbf +0 -0
- data/test/data/multipoint.shp +0 -0
- data/test/data/multipoint.shx +0 -0
- data/test/data/point.dbf +0 -0
- data/test/data/point.shp +0 -0
- data/test/data/point.shx +0 -0
- data/test/data/polygon.dbf +0 -0
- data/test/data/polygon.shp +0 -0
- data/test/data/polygon.shx +0 -0
- data/test/data/polyline.dbf +0 -0
- data/test/data/polyline.shp +0 -0
- data/test/data/polyline.shx +0 -0
- data/test/test_ewkb_parser.rb +171 -0
- data/test/test_ewkt_parser.rb +193 -0
- data/test/test_georss_kml.rb +231 -0
- data/test/test_shp.rb +76 -0
- data/test/test_shp_write.rb +150 -0
- data/test/test_simple_features.rb +506 -0
- data/tools/db.yml +6 -0
- data/tools/shp2sql.rb +92 -0
- metadata +95 -0
data/tools/db.yml
ADDED
data/tools/shp2sql.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
$:.unshift("lib/spatial_adapter/","lib/spatial_adapter/lib")
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'geo_ruby'
|
5
|
+
include GeoRuby::Shp4r
|
6
|
+
|
7
|
+
require 'active_record'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
def shp_field_type_2_rails(type)
|
11
|
+
case type
|
12
|
+
when 'N' then :integer
|
13
|
+
when 'F' then :float
|
14
|
+
when 'D' then :date
|
15
|
+
else
|
16
|
+
:string
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def shp_geom_type_2_rails(type)
|
21
|
+
case type
|
22
|
+
when ShpType::POINT then :point
|
23
|
+
when ShpType::POLYLINE then :multi_line_string
|
24
|
+
when ShpType::POLYGON then :multi_polygon
|
25
|
+
when ShpType::MULTIPOINT then :multi_point
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#create an active record connection to a database
|
30
|
+
ActiveRecord::Base.establish_connection(YAML.load_file('db.yml'))
|
31
|
+
|
32
|
+
#add options depending on the type of database
|
33
|
+
if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
|
34
|
+
options = "TYPE=MyISAM" #for MySQL <= 5.0.16 : only MyISAM tables support geometric types
|
35
|
+
else
|
36
|
+
options = ""
|
37
|
+
end
|
38
|
+
|
39
|
+
#load the correct spatial adapter depending on the type of the selected database : the required file is called init since it is originally a rails plugin and that's what the entry file for the plugin has to be called
|
40
|
+
require 'init'
|
41
|
+
|
42
|
+
#go through all the shp files passed as argument
|
43
|
+
ARGV.each do |shp|
|
44
|
+
shp_basename = File.basename(shp)
|
45
|
+
if shp_basename =~ /(.*)\.shp/
|
46
|
+
table_name = $1.downcase
|
47
|
+
|
48
|
+
#drop in case it already exists
|
49
|
+
begin
|
50
|
+
ActiveRecord::Schema.drop_table(table_name)
|
51
|
+
rescue
|
52
|
+
end
|
53
|
+
|
54
|
+
#empty block : the columns will be added afterwards
|
55
|
+
ActiveRecord::Schema.create_table(table_name,:options => options){}
|
56
|
+
|
57
|
+
ShpFile.open(shp) do |shp|
|
58
|
+
shp.fields.each do |field|
|
59
|
+
ActiveRecord::Schema.add_column(table_name, field.name.downcase, shp_field_type_2_rails(field.type))
|
60
|
+
end
|
61
|
+
|
62
|
+
#add the geometric column in the_geom
|
63
|
+
ActiveRecord::Schema.add_column(table_name,"the_geom",shp_geom_type_2_rails(shp.shp_type),:null => false)
|
64
|
+
#add an index
|
65
|
+
ActiveRecord::Schema.add_index(table_name,"the_geom",:spatial => true)
|
66
|
+
|
67
|
+
#add the data
|
68
|
+
#create a subclass of ActiveRecord::Base wired to the table just created
|
69
|
+
arTable = Class.new(ActiveRecord::Base) do
|
70
|
+
set_table_name table_name
|
71
|
+
end
|
72
|
+
|
73
|
+
#go though all the shapes in the file
|
74
|
+
shp.each do |shape|
|
75
|
+
#create an ActiveRecord object
|
76
|
+
record = arTable.new
|
77
|
+
|
78
|
+
#fill the fields
|
79
|
+
shp.fields.each do |field|
|
80
|
+
record[field.name.downcase] = shape.data[field.name]
|
81
|
+
end
|
82
|
+
|
83
|
+
#fill the geometry
|
84
|
+
record.the_geom = shape.geometry
|
85
|
+
|
86
|
+
#save to the database
|
87
|
+
record.save
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsl-GeoRuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guilhem Vellut
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: GeoRuby is intended as a holder for data returned from PostGIS and MySQL Spatial queries. The data model roughly follows the OGC "Simple Features for SQL" specification (see www.opengis.org/docs/99-049.pdf), although without any kind of advanced functionalities (such as geometric operators or reprojections).
|
17
|
+
email: guilhem.vellut@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- tools/shp2sql.rb
|
26
|
+
- tools/db.yml
|
27
|
+
- test/test_simple_features.rb
|
28
|
+
- test/test_shp_write.rb
|
29
|
+
- test/test_shp.rb
|
30
|
+
- test/test_georss_kml.rb
|
31
|
+
- test/test_ewkt_parser.rb
|
32
|
+
- test/test_ewkb_parser.rb
|
33
|
+
- test/data/polyline.shx
|
34
|
+
- test/data/polyline.shp
|
35
|
+
- test/data/polyline.dbf
|
36
|
+
- test/data/polygon.shx
|
37
|
+
- test/data/polygon.shp
|
38
|
+
- test/data/polygon.dbf
|
39
|
+
- test/data/point.shx
|
40
|
+
- test/data/point.shp
|
41
|
+
- test/data/point.dbf
|
42
|
+
- test/data/multipoint.shx
|
43
|
+
- test/data/multipoint.shp
|
44
|
+
- test/data/multipoint.dbf
|
45
|
+
- README
|
46
|
+
- rakefile.rb
|
47
|
+
- MIT-LICENSE
|
48
|
+
- lib/geo_ruby.rb
|
49
|
+
- lib/geo_ruby/simple_features/polygon.rb
|
50
|
+
- lib/geo_ruby/simple_features/point.rb
|
51
|
+
- lib/geo_ruby/simple_features/multi_polygon.rb
|
52
|
+
- lib/geo_ruby/simple_features/multi_point.rb
|
53
|
+
- lib/geo_ruby/simple_features/multi_line_string.rb
|
54
|
+
- lib/geo_ruby/simple_features/linear_ring.rb
|
55
|
+
- lib/geo_ruby/simple_features/line_string.rb
|
56
|
+
- lib/geo_ruby/simple_features/helper.rb
|
57
|
+
- lib/geo_ruby/simple_features/georss_parser.rb
|
58
|
+
- lib/geo_ruby/simple_features/geometry_factory.rb
|
59
|
+
- lib/geo_ruby/simple_features/geometry_collection.rb
|
60
|
+
- lib/geo_ruby/simple_features/geometry.rb
|
61
|
+
- lib/geo_ruby/simple_features/ewkt_parser.rb
|
62
|
+
- lib/geo_ruby/simple_features/ewkb_parser.rb
|
63
|
+
- lib/geo_ruby/simple_features/envelope.rb
|
64
|
+
- lib/geo_ruby/shp4r/shp.rb
|
65
|
+
- lib/geo_ruby/shp4r/dbf.rb
|
66
|
+
- georuby.gemspec
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://georuby.rubyforge.org/
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --inline-source
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project: georuby
|
90
|
+
rubygems_version: 1.2.0
|
91
|
+
signing_key:
|
92
|
+
specification_version: 2
|
93
|
+
summary: Ruby data holder for OGC Simple Features
|
94
|
+
test_files: []
|
95
|
+
|