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
@@ -0,0 +1,231 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'geo_ruby'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
include GeoRuby::SimpleFeatures
|
7
|
+
|
8
|
+
class TestGeorssKml < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_point_creation
|
11
|
+
point = Point.from_x_y(3,4)
|
12
|
+
|
13
|
+
assert_equal("<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\">4 3</georss:point>", point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n",""))
|
14
|
+
assert_equal("<geo:lat>4</geo:lat><geo:long>3</geo:long>",point.as_georss(:dialect => :w3cgeo).gsub("\n",""))
|
15
|
+
assert_equal("<georss:where><gml:Point><gml:pos>4 3</gml:pos></gml:Point></georss:where>",point.as_georss(:dialect => :gml).gsub("\n",""))
|
16
|
+
|
17
|
+
assert_equal("<Point id=\"HOYOYO-42\"><coordinates>3,4</coordinates></Point>",point.as_kml(:id => "HOYOYO-42").gsub("\n",""))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_line_string
|
21
|
+
ls = LineString.from_points([Point.from_lon_lat_z(12.4,-45.3,56),Point.from_lon_lat_z(45.4,41.6,45)],123,true)
|
22
|
+
|
23
|
+
assert_equal("<georss:line>-45.3 12.4 41.6 45.4</georss:line>",ls.as_georss.gsub("\n",""))
|
24
|
+
assert_equal("<geo:lat>-45.3</geo:lat><geo:long>12.4</geo:long>",ls.as_georss(:dialect => :w3cgeo).gsub("\n",""))
|
25
|
+
assert_equal("<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>",ls.as_georss(:dialect => :gml).gsub("\n",""))
|
26
|
+
|
27
|
+
assert_equal("<LineString><extrude>1</extrude><altitudeMode>absolute</altitudeMode><coordinates>12.4,-45.3,56 45.4,41.6,45</coordinates></LineString>",ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n",""))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_polygon
|
31
|
+
linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
|
32
|
+
linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
|
33
|
+
polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
|
34
|
+
|
35
|
+
assert_equal("<hoyoyo:polygon>-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4</hoyoyo:polygon>",polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n",""))
|
36
|
+
assert_equal("<bouyoul:lat>-45.3</bouyoul:lat><bouyoul:long>12.4</bouyoul:long>",polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n",""))
|
37
|
+
assert_equal("<georss:where><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></georss:where>",polygon.as_georss(:dialect => :gml).gsub("\n",""))
|
38
|
+
|
39
|
+
assert_equal("<Polygon><outerBoundaryIs><LinearRing><coordinates>12.4,-45.3 45.4,41.6 4.456,1.0698 12.4,-45.3</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>2.4,5.3 5.4,1.4263 14.46,1.06 2.4,5.3</coordinates></LinearRing></innerBoundaryIs></Polygon>",polygon.as_kml.gsub("\n",""))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_geometry_collection
|
43
|
+
gc = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
|
44
|
+
|
45
|
+
#only the first geometry is output
|
46
|
+
assert_equal("<georss:point floor=\"4\">45.4 4.67</georss:point>",gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n",""))
|
47
|
+
assert_equal("<geo:lat>45.4</geo:lat><geo:long>4.67</geo:long>",gc.as_georss(:dialect => :w3cgeo).gsub("\n",""))
|
48
|
+
assert_equal("<georss:where><gml:Point><gml:pos>45.4 4.67</gml:pos></gml:Point></georss:where>",gc.as_georss(:dialect => :gml).gsub("\n",""))
|
49
|
+
|
50
|
+
assert_equal("<MultiGeometry id=\"HOYOYO-42\"><Point><coordinates>4.67,45.4</coordinates></Point><LineString><coordinates>5.7,12.45 67.55,54</coordinates></LineString></MultiGeometry>",gc.as_kml(:id => "HOYOYO-42").gsub("\n",""))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_envelope
|
54
|
+
linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,5],[45.4,41.6,6],[4.456,1.0698,8],[12.4,-45.3,3.5]],256,true)
|
55
|
+
linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,9.0],[5.4,1.4263,-5.4],[14.46,1.06,34],[2.4,5.3,3.14]],256,true)
|
56
|
+
polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true)
|
57
|
+
|
58
|
+
e = polygon.envelope
|
59
|
+
|
60
|
+
assert_equal("<georss:box>-45.3 4.456 41.6 45.4</georss:box>",e.as_georss(:dialect => :simple).gsub("\n",""))
|
61
|
+
#center
|
62
|
+
assert_equal("<geo:lat>-1.85</geo:lat><geo:long>24.928</geo:long>",e.as_georss(:dialect => :w3cgeo).gsub("\n",""))
|
63
|
+
assert_equal("<georss:where><gml:Envelope><gml:LowerCorner>-45.3 4.456</gml:LowerCorner><gml:UpperCorner>41.6 45.4</gml:UpperCorner></gml:Envelope></georss:where>",e.as_georss(:dialect => :gml).gsub("\n",""))
|
64
|
+
|
65
|
+
assert_equal("<LatLonAltBox><north>41.6</north><south>-45.3</south><east>45.4</east><west>4.456</west><minAltitude>-5.4</minAltitude><maxAltitude>34</maxAltitude></LatLonAltBox>",e.as_kml.gsub("\n",""))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_point_georss_read
|
69
|
+
#W3CGeo
|
70
|
+
str = " <geo:lat >12.3</geo:lat >\n\t <geo:long> 4.56</geo:long> "
|
71
|
+
geom = Geometry.from_georss(str)
|
72
|
+
assert_equal(geom.class, Point)
|
73
|
+
assert_equal(12.3, geom.lat)
|
74
|
+
assert_equal(4.56, geom.lon)
|
75
|
+
|
76
|
+
str = " <geo:Point> \n \t <geo:long> 4.56</geo:long> \n\t <geo:lat >12.3</geo:lat > </geo:Point> "
|
77
|
+
geom = Geometry.from_georss(str)
|
78
|
+
assert_equal(geom.class, Point)
|
79
|
+
assert_equal(12.3, geom.lat)
|
80
|
+
assert_equal(4.56, geom.lon)
|
81
|
+
|
82
|
+
#gml
|
83
|
+
str = " <georss:where> \t\r <gml:Point > \t <gml:pos> 4 \t 3 </gml:pos> </gml:Point> </georss:where>"
|
84
|
+
geom = Geometry.from_georss(str)
|
85
|
+
assert_equal(geom.class, Point)
|
86
|
+
assert_equal(4, geom.lat)
|
87
|
+
assert_equal(3, geom.lon)
|
88
|
+
|
89
|
+
|
90
|
+
#simple
|
91
|
+
str = "<georss:point > 4 \r\t 3 \t</georss:point >"
|
92
|
+
geom = Geometry.from_georss(str)
|
93
|
+
assert_equal(geom.class, Point)
|
94
|
+
assert_equal(4, geom.lat)
|
95
|
+
assert_equal(3, geom.lon)
|
96
|
+
|
97
|
+
#simple with tags
|
98
|
+
str = "<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\" \n floor=\"2\" relationshiptag=\"puyopuyo\" radius=\"42\" > 4 \n 3 \t</georss:point >"
|
99
|
+
geom,tags = Geometry.from_georss_with_tags(str)
|
100
|
+
assert_equal(geom.class, Point)
|
101
|
+
assert_equal(4, geom.lat)
|
102
|
+
assert_equal(3, geom.lon)
|
103
|
+
assert_equal("hoyoyo",tags.featuretypetag)
|
104
|
+
assert_equal(45.7,tags.elev)
|
105
|
+
assert_equal("puyopuyo",tags.relationshiptag)
|
106
|
+
assert_equal(2,tags.floor)
|
107
|
+
assert_equal(42,tags.radius)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_line_string_georss_read
|
111
|
+
ls = LineString.from_points([Point.from_lon_lat(12.4,-45.3),Point.from_lon_lat(45.4,41.6)])
|
112
|
+
|
113
|
+
str = "<georss:line > -45.3 12.4 \n \r41.6\t 45.4</georss:line>"
|
114
|
+
geom = Geometry.from_georss(str)
|
115
|
+
assert_equal(geom.class, LineString)
|
116
|
+
assert_equal(ls ,geom)
|
117
|
+
|
118
|
+
str = "<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>"
|
119
|
+
geom = Geometry.from_georss(str)
|
120
|
+
assert_equal(geom.class, LineString)
|
121
|
+
assert_equal(ls ,geom)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_polygon_georss_read
|
126
|
+
linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]])
|
127
|
+
polygon = Polygon.from_linear_rings([linear_ring])
|
128
|
+
|
129
|
+
str = "<hoyoyo:polygon featuretypetag=\"42\" > -45.3 12.4 41.6 \n\r 45.4 1.0698 \r 4.456 -45.3 12.4 </hoyoyo:polygon>"
|
130
|
+
geom = Geometry.from_georss(str)
|
131
|
+
assert_equal(geom.class, Polygon)
|
132
|
+
assert_equal(polygon, geom)
|
133
|
+
|
134
|
+
str = "<georss:where>\r\t \n <gml:Polygon><gml:exterior> <gml:LinearRing><gml:posList> -45.3 \n\r 12.4 41.6 \n\t 45.4 1.0698 4.456 -45.3 12.4</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></georss:where>"
|
135
|
+
geom = Geometry.from_georss(str)
|
136
|
+
assert_equal(geom.class, Polygon)
|
137
|
+
assert_equal(polygon, geom)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_envelope_georss_read
|
141
|
+
|
142
|
+
e = Envelope.from_coordinates([[4.456,-45.3],[45.4,41.6]])
|
143
|
+
|
144
|
+
str = "<georss:box >-45.3 4.456 \n41.6 45.4</georss:box>"
|
145
|
+
geom = Geometry.from_georss(str)
|
146
|
+
assert_equal(geom.class, Envelope)
|
147
|
+
assert_equal(e, geom)
|
148
|
+
|
149
|
+
str = "<georss:where><gml:Envelope><gml:lowerCorner>-45.3 \n 4.456</gml:lowerCorner><gml:upperCorner>41.6 \t\n 45.4</gml:upperCorner></gml:Envelope></georss:where>"
|
150
|
+
geom = Geometry.from_georss(str)
|
151
|
+
assert_equal(geom.class, Envelope)
|
152
|
+
assert_equal(e, geom)
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_kml_read
|
157
|
+
g = Geometry.from_kml("<Point><coordinates>45,12,25</coordinates></Point>")
|
158
|
+
assert(g.is_a?(Point))
|
159
|
+
assert_equal(g,Point.from_x_y_z(45,12,25))
|
160
|
+
|
161
|
+
g = Geometry.from_kml("<LineString>
|
162
|
+
<extrude>1</extrude>
|
163
|
+
<tessellate>1</tessellate>
|
164
|
+
<coordinates>
|
165
|
+
-122.364383,37.824664,0 -122.364152,37.824322,0
|
166
|
+
</coordinates>
|
167
|
+
</LineString>")
|
168
|
+
assert(g.is_a?(LineString))
|
169
|
+
assert(2,g.length)
|
170
|
+
assert_equal(LineString.from_points([Point.from_x_y_z(-122.364383,37.824664,0),Point.from_x_y_z(-122.364152,37.824322,0)],DEFAULT_SRID,true),g)
|
171
|
+
|
172
|
+
g = Geometry.from_kml("<Polygon>
|
173
|
+
<extrude>1</extrude>
|
174
|
+
<altitudeMode>relativeToGround</altitudeMode>
|
175
|
+
<outerBoundaryIs>
|
176
|
+
<LinearRing>
|
177
|
+
<coordinates>
|
178
|
+
-122.366278,37.818844,30
|
179
|
+
-122.365248,37.819267,30
|
180
|
+
-122.365640,37.819861,30
|
181
|
+
-122.366669,37.819429,30
|
182
|
+
-122.366278,37.818844,30
|
183
|
+
</coordinates>
|
184
|
+
</LinearRing>
|
185
|
+
</outerBoundaryIs>
|
186
|
+
<innerBoundaryIs>
|
187
|
+
<LinearRing>
|
188
|
+
<coordinates>
|
189
|
+
-122.366212,37.818977,30
|
190
|
+
-122.365424,37.819294,30
|
191
|
+
-122.365704,37.819731,30
|
192
|
+
-122.366488,37.819402,30
|
193
|
+
-122.366212,37.818977,30
|
194
|
+
</coordinates>
|
195
|
+
</LinearRing>
|
196
|
+
</innerBoundaryIs>
|
197
|
+
<innerBoundaryIs>
|
198
|
+
<LinearRing>
|
199
|
+
<coordinates>
|
200
|
+
-122.366212,37.818977,30
|
201
|
+
-122.365424,37.819294,30
|
202
|
+
-122.365704,37.819731,30
|
203
|
+
-122.366488,37.819402,30
|
204
|
+
-122.366212,37.818977,30
|
205
|
+
</coordinates>
|
206
|
+
</LinearRing>
|
207
|
+
</innerBoundaryIs>
|
208
|
+
</Polygon>")
|
209
|
+
assert(g.is_a?(Polygon))
|
210
|
+
assert_equal(3,g.length)
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_to_kml_for_point_does_not_raise_type_error_if_geom_data_not_provided
|
215
|
+
point = Point.from_coordinates([1.6,2.8],123)
|
216
|
+
assert_nothing_raised(TypeError) { point.kml_representation }
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_to_kml_for_polygon_does_not_raise_type_error_if_geom_data_not_provided
|
220
|
+
polygon = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256)
|
221
|
+
|
222
|
+
assert_nothing_raised(TypeError) { polygon.kml_representation }
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_to_kml_for_line_string_does_not_raise_type_error_if_geom_data_not_provided
|
226
|
+
ls = LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
227
|
+
assert_nothing_raised(TypeError) { ls.kml_representation }
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
end
|
data/test/test_shp.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'geo_ruby'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
include GeoRuby::SimpleFeatures
|
7
|
+
include GeoRuby::Shp4r
|
8
|
+
|
9
|
+
class TestShp < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_point
|
12
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/point.shp')
|
13
|
+
|
14
|
+
assert_equal(2,shpfile.record_count)
|
15
|
+
assert_equal(1,shpfile.fields.length)
|
16
|
+
assert_equal(ShpType::POINT,shpfile.shp_type)
|
17
|
+
field = shpfile.fields[0]
|
18
|
+
assert_equal("Hoyoyo",field.name)
|
19
|
+
assert_equal("N",field.type)
|
20
|
+
|
21
|
+
record1 = shpfile[0]
|
22
|
+
assert(record1.geometry.kind_of?(Point))
|
23
|
+
assert_in_delta(-90.08375,record1.geometry.x,0.00001)
|
24
|
+
assert_in_delta(34.39996,record1.geometry.y,0.00001)
|
25
|
+
assert_equal(6,record1.data['Hoyoyo'])
|
26
|
+
|
27
|
+
record2 = shpfile[1]
|
28
|
+
assert(record1.geometry.kind_of?(Point))
|
29
|
+
assert_in_delta(-87.82580,record2.geometry.x,0.00001)
|
30
|
+
assert_in_delta(33.36417,record2.geometry.y,0.00001)
|
31
|
+
assert_equal(9,record2.data['Hoyoyo'])
|
32
|
+
|
33
|
+
shpfile.close
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_polyline
|
37
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polyline.shp')
|
38
|
+
|
39
|
+
assert_equal(1,shpfile.record_count)
|
40
|
+
assert_equal(1,shpfile.fields.length)
|
41
|
+
assert_equal(ShpType::POLYLINE,shpfile.shp_type)
|
42
|
+
field = shpfile.fields[0]
|
43
|
+
assert_equal("Chipoto",field.name)
|
44
|
+
assert_equal("F",field.type)
|
45
|
+
|
46
|
+
record1 = shpfile[0]
|
47
|
+
#a SHP polyline can have multiple parts so they are in fact multilinestrings
|
48
|
+
assert(record1.geometry.kind_of?(MultiLineString))
|
49
|
+
assert_equal(1,record1.geometry.length)
|
50
|
+
assert_equal(6,record1.geometry[0].length)
|
51
|
+
assert_equal(5.678,record1.data['Chipoto'])
|
52
|
+
|
53
|
+
shpfile.close
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_polygon
|
57
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polygon.shp')
|
58
|
+
|
59
|
+
assert_equal(1,shpfile.record_count)
|
60
|
+
assert_equal(1,shpfile.fields.length)
|
61
|
+
assert_equal(ShpType::POLYGON,shpfile.shp_type)
|
62
|
+
field = shpfile.fields[0]
|
63
|
+
assert_equal("Hello",field.name)
|
64
|
+
assert_equal("C",field.type)
|
65
|
+
|
66
|
+
record1 = shpfile[0]
|
67
|
+
#a SHP polygon can have multiple outer loops (although not supported currently) so they are in fact multipolygons
|
68
|
+
assert(record1.geometry.kind_of?(MultiPolygon))
|
69
|
+
assert_equal(1,record1.geometry.length)
|
70
|
+
assert_equal(1,record1.geometry[0].length)
|
71
|
+
assert_equal(7,record1.geometry[0][0].length)
|
72
|
+
assert_equal("Bouyoul!",record1.data['Hello'])
|
73
|
+
|
74
|
+
shpfile.close
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'geo_ruby'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
include GeoRuby::SimpleFeatures
|
7
|
+
include GeoRuby::Shp4r
|
8
|
+
|
9
|
+
class TestShp < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def cp_all_shp(file1,file2)
|
12
|
+
FileUtils.copy(file1 + ".shp",file2 + ".shp")
|
13
|
+
FileUtils.copy(file1 + ".shx",file2 + ".shx")
|
14
|
+
FileUtils.copy(file1 + ".dbf",file2 + ".dbf")
|
15
|
+
end
|
16
|
+
|
17
|
+
def rm_all_shp(file)
|
18
|
+
FileUtils.rm(file + ".shp")
|
19
|
+
FileUtils.rm(file + ".shx")
|
20
|
+
FileUtils.rm(file + ".dbf")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_point
|
24
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/point',
|
25
|
+
File.dirname(__FILE__) + '/data/point2')
|
26
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/point2.shp')
|
27
|
+
|
28
|
+
shpfile.transaction do |tr|
|
29
|
+
assert(tr.instance_of?(ShpTransaction))
|
30
|
+
tr.add(ShpRecord.new(Point.from_x_y(123.4,123.4),'Hoyoyo' => 5))
|
31
|
+
tr.add(ShpRecord.new(Point.from_x_y(-16.67,16.41),'Hoyoyo' => -7))
|
32
|
+
tr.delete(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal(3,shpfile.record_count)
|
36
|
+
|
37
|
+
shpfile.close
|
38
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/point2')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_linestring
|
42
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/polyline',
|
43
|
+
File.dirname(__FILE__) + '/data/polyline2')
|
44
|
+
|
45
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polyline2.shp')
|
46
|
+
|
47
|
+
shpfile.transaction do |tr|
|
48
|
+
assert(tr.instance_of?(ShpTransaction))
|
49
|
+
tr.add(ShpRecord.new(LineString.from_coordinates([[123.4,123.4],[45.6,12.3]]),'Chipoto' => 5.6778))
|
50
|
+
tr.add(ShpRecord.new(LineString.from_coordinates([[23.4,13.4],[45.6,12.3],[12,-67]]),'Chipoto' => -7.1))
|
51
|
+
tr.delete(0)
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal(2,shpfile.record_count)
|
55
|
+
shpfile.close
|
56
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/polyline2')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_polygon
|
60
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/polygon',
|
61
|
+
File.dirname(__FILE__) + '/data/polygon2')
|
62
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polygon2.shp')
|
63
|
+
|
64
|
+
shpfile.transaction do |tr|
|
65
|
+
assert(tr.instance_of?(ShpTransaction))
|
66
|
+
tr.delete(0)
|
67
|
+
tr.add(ShpRecord.new(Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]]),'Hello' => "oook"))
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_equal(1,shpfile.record_count)
|
71
|
+
|
72
|
+
shpfile.close
|
73
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/polygon2')
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_multipoint
|
77
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/multipoint',
|
78
|
+
File.dirname(__FILE__) + '/data/multipoint2')
|
79
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/multipoint2.shp')
|
80
|
+
|
81
|
+
shpfile.transaction do |tr|
|
82
|
+
assert(tr.instance_of?(ShpTransaction))
|
83
|
+
tr.add(ShpRecord.new(MultiPoint.from_coordinates([[45.6,-45.1],[12.4,98.2],[51.2,-0.12],[156.12345,56.109]]),'Hello' => 5,"Hoyoyo" => "AEZAE"))
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal(2,shpfile.record_count)
|
87
|
+
|
88
|
+
shpfile.close
|
89
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/multipoint2')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_multi_polygon
|
93
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/polygon',
|
94
|
+
File.dirname(__FILE__) + '/data/polygon4')
|
95
|
+
|
96
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polygon4.shp')
|
97
|
+
|
98
|
+
shpfile.transaction do |tr|
|
99
|
+
assert(tr.instance_of?(ShpTransaction))
|
100
|
+
tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook"))
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_equal(2,shpfile.record_count)
|
104
|
+
|
105
|
+
shpfile.close
|
106
|
+
|
107
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/polygon4')
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_rollback
|
111
|
+
cp_all_shp(File.dirname(__FILE__) + '/data/polygon',
|
112
|
+
File.dirname(__FILE__) + '/data/polygon5')
|
113
|
+
|
114
|
+
shpfile = ShpFile.open(File.dirname(__FILE__) + '/data/polygon5.shp')
|
115
|
+
|
116
|
+
shpfile.transaction do |tr|
|
117
|
+
assert(tr.instance_of?(ShpTransaction))
|
118
|
+
tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook"))
|
119
|
+
tr.rollback
|
120
|
+
end
|
121
|
+
assert_equal(1,shpfile.record_count)
|
122
|
+
|
123
|
+
shpfile.close
|
124
|
+
|
125
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/polygon5')
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_creation
|
130
|
+
shpfile = ShpFile.create(File.dirname(__FILE__) + '/data/point3.shp',ShpType::POINT,[Dbf::Field.new("Hoyoyo","C",10,0)])
|
131
|
+
shpfile.transaction do |tr|
|
132
|
+
tr.add(ShpRecord.new(Point.from_x_y(123,123.4),'Hoyoyo' => "HJHJJ"))
|
133
|
+
end
|
134
|
+
assert(1,shpfile.record_count)
|
135
|
+
shpfile.close
|
136
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/point3')
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_creation_multipoint
|
140
|
+
shpfile = ShpFile.create(File.dirname(__FILE__) + '/data/multipoint3.shp',ShpType::MULTIPOINT,[Dbf::Field.new("Hoyoyo","C",10),Dbf::Field.new("Hello","N",10)])
|
141
|
+
shpfile.transaction do |tr|
|
142
|
+
tr.add(ShpRecord.new(MultiPoint.from_coordinates([[123,123.4],[345,12.2]]),'Hoyoyo' => "HJHJJ","Hello" => 5))
|
143
|
+
end
|
144
|
+
assert(1,shpfile.record_count)
|
145
|
+
shpfile.close
|
146
|
+
rm_all_shp(File.dirname(__FILE__) + '/data/multipoint3')
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
end
|