source: anuga_core/source/anuga/geospatial_data/test_geospatial_data.py @ 3663

Last change on this file since 3663 was 3663, checked in by duncan, 17 years ago

added tests

File size: 46.5 KB
Line 
1#!/usr/bin/env python
2
3
4import unittest
5import os
6from Numeric import zeros, array, allclose, concatenate
7from math import sqrt, pi
8import tempfile
9
10from anuga.geospatial_data.geospatial_data import *
11from anuga.coordinate_transforms.geo_reference import Geo_reference, TitleError
12from anuga.coordinate_transforms.redfearn import degminsec2decimal_degrees
13
14
15class Test_Geospatial_data(unittest.TestCase):
16    def setUp(self):
17        pass
18
19    def tearDown(self):
20        pass
21
22
23    def test_0(self):
24        """Basic points
25        """
26        from anuga.coordinate_transforms.geo_reference import Geo_reference
27       
28        points = [[1.0, 2.1], [3.0, 5.3]]
29        G = Geospatial_data(points)
30
31        assert allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]])
32
33        #Check defaults
34        assert G.attributes is None
35       
36        assert G.geo_reference.zone == Geo_reference().zone
37        assert G.geo_reference.xllcorner == Geo_reference().xllcorner
38        assert G.geo_reference.yllcorner == Geo_reference().yllcorner
39       
40
41    def test_1(self):
42        points = [[1.0, 2.1], [3.0, 5.3]]
43        attributes = [2, 4]
44        G = Geospatial_data(points, attributes)       
45
46        assert G.attributes.keys()[0] == 'attribute'
47        assert allclose(G.attributes.values()[0], [2, 4])
48       
49
50    def test_2(self):
51        from anuga.coordinate_transforms.geo_reference import Geo_reference
52        points = [[1.0, 2.1], [3.0, 5.3]]
53        attributes = [2, 4]
54        G = Geospatial_data(points, attributes,
55                            geo_reference=Geo_reference(56, 100, 200))
56
57        assert G.geo_reference.zone == 56
58        assert G.geo_reference.xllcorner == 100
59        assert G.geo_reference.yllcorner == 200
60
61
62    def test_get_attributes_1(self):
63        from anuga.coordinate_transforms.geo_reference import Geo_reference
64        points = [[1.0, 2.1], [3.0, 5.3]]
65        attributes = [2, 4]
66        G = Geospatial_data(points, attributes,
67                            geo_reference=Geo_reference(56, 100, 200))
68
69
70        P = G.get_data_points(absolute=False)
71        assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
72
73        P = G.get_data_points(absolute=True)
74        assert allclose(P, [[101.0, 202.1], [103.0, 205.3]])       
75
76        V = G.get_attributes() #Simply get them
77        assert allclose(V, [2, 4])
78
79        V = G.get_attributes('attribute') #Get by name
80        assert allclose(V, [2, 4])
81
82    def test_get_attributes_2(self):
83        """Multiple attributes
84        """
85       
86        from anuga.coordinate_transforms.geo_reference import Geo_reference
87        points = [[1.0, 2.1], [3.0, 5.3]]
88        attributes = {'a0': [0, 0], 'a1': [2, 4], 'a2': [79.4, -7]}
89        G = Geospatial_data(points, attributes,
90                            geo_reference=Geo_reference(56, 100, 200),
91                            default_attribute_name='a1')
92
93
94        P = G.get_data_points(absolute=False)
95        assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
96       
97        V = G.get_attributes() #Get default attribute
98        assert allclose(V, [2, 4])
99
100        V = G.get_attributes('a0') #Get by name
101        assert allclose(V, [0, 0])
102
103        V = G.get_attributes('a1') #Get by name
104        assert allclose(V, [2, 4])
105
106        V = G.get_attributes('a2') #Get by name
107        assert allclose(V, [79.4, -7])
108
109        try:
110            V = G.get_attributes('hdnoatedu') #Invalid
111        except AssertionError:
112            pass
113        else:
114            raise 'Should have raised exception' 
115
116    def test_get_data_points(self):
117        points_ab = [[12.5,34.7],[-4.5,-60.0]]
118        x_p = -10
119        y_p = -40
120        geo_ref = Geo_reference(56, x_p, y_p)
121        points_rel = geo_ref.change_points_geo_ref(points_ab)
122       
123        spatial = Geospatial_data(points_rel, geo_reference=geo_ref)
124
125        results = spatial.get_data_points(absolute=False)
126       
127        assert allclose(results, points_rel)
128       
129        x_p = -1770
130        y_p = 4.01
131        geo_ref = Geo_reference(56, x_p, y_p)
132        points_rel = geo_ref.change_points_geo_ref(points_ab)
133        results = spatial.get_data_points \
134                  ( geo_reference=geo_ref)
135       
136        assert allclose(results, points_rel)
137
138       
139    def test_set_geo_reference(self):
140        points_ab = [[12.5,34.7],[-4.5,-60.0]]
141        x_p = -10
142        y_p = -40
143        geo_ref = Geo_reference(56, x_p, y_p)
144        points_rel = geo_ref.change_points_geo_ref(points_ab)
145        spatial = Geospatial_data(points_rel)
146        # since the geo_ref wasn't set
147        assert not allclose( points_ab, spatial.get_data_points(absolute=True))
148       
149        spatial = Geospatial_data(points_rel, geo_reference=geo_ref)
150        assert allclose( points_ab, spatial.get_data_points(absolute=True))
151       
152        x_p = 10
153        y_p = 400
154        new_geo_ref = Geo_reference(56, x_p, y_p)
155        spatial.set_geo_reference(new_geo_ref)
156        assert allclose( points_ab, spatial.get_data_points(absolute=True))
157       
158       
159       
160    def test_conversions_to_points_dict(self):
161        """test conversions to points_dict
162        """
163       
164        from anuga.coordinate_transforms.geo_reference import Geo_reference
165        points = [[1.0, 2.1], [3.0, 5.3]]
166        attributes = {'a0': [0, 0], 'a1': [2, 4], 'a2': [79.4, -7]}
167        G = Geospatial_data(points, attributes,
168                            geo_reference=Geo_reference(56, 100, 200),
169                            default_attribute_name='a1')
170
171
172        points_dict = geospatial_data2points_dictionary(G)
173
174        assert points_dict.has_key('pointlist')
175        assert points_dict.has_key('attributelist')       
176        assert points_dict.has_key('geo_reference')
177
178        assert allclose( points_dict['pointlist'], points )
179
180        A = points_dict['attributelist']
181        assert A.has_key('a0')
182        assert A.has_key('a1')
183        assert A.has_key('a2')       
184
185        assert allclose( A['a0'], [0, 0] )
186        assert allclose( A['a1'], [2, 4] )       
187        assert allclose( A['a2'], [79.4, -7] )
188
189
190        geo = points_dict['geo_reference']
191        assert geo is G.geo_reference
192
193
194    def test_conversions_from_points_dict(self):
195        """test conversions from points_dict
196        """
197
198        from anuga.coordinate_transforms.geo_reference import Geo_reference
199       
200        points = [[1.0, 2.1], [3.0, 5.3]]
201        attributes = {'a0': [0, 0], 'a1': [2, 4], 'a2': [79.4, -7]}
202
203        points_dict = {}
204        points_dict['pointlist'] = points
205        points_dict['attributelist'] = attributes
206        points_dict['geo_reference'] = Geo_reference(56, 100, 200)
207       
208
209        G = points_dictionary2geospatial_data(points_dict)
210
211        P = G.get_data_points(absolute=False)
212        assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
213       
214        #V = G.get_attribute_values() #Get default attribute
215        #assert allclose(V, [2, 4])
216
217        V = G.get_attributes('a0') #Get by name
218        assert allclose(V, [0, 0])
219
220        V = G.get_attributes('a1') #Get by name
221        assert allclose(V, [2, 4])
222
223        V = G.get_attributes('a2') #Get by name
224        assert allclose(V, [79.4, -7])
225
226    def test_add(self):
227        """ test the addition of two geospatical objects
228            no geo_reference see next test
229        """
230        points = [[1.0, 2.1], [3.0, 5.3]]
231        attributes = {'depth':[2, 4], 'elevation':[6.1, 5]}
232        attributes1 = {'depth':[2, 4], 'elevation':[2.5, 1]}
233        G1 = Geospatial_data(points, attributes)       
234        G2 = Geospatial_data(points, attributes1) 
235       
236#        g3 = geospatial_data2points_dictionary(G1)
237#        print 'g3=', g3
238       
239        G = G1 + G2
240
241        assert G.attributes.has_key('depth')
242        assert G.attributes.has_key('elevation')
243        assert allclose(G.attributes['depth'], [2, 4, 2, 4])
244        assert allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1])
245        assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
246                                              [1.0, 2.1], [3.0, 5.3]])
247       
248    def test_addII(self):
249        """ test the addition of two geospatical objects
250            no geo_reference see next test
251        """
252        points = [[1.0, 2.1], [3.0, 5.3]]
253        attributes = {'depth':[2, 4]}
254        G1 = Geospatial_data(points, attributes) 
255       
256        points = [[5.0, 2.1], [3.0, 50.3]]
257        attributes = {'depth':[200, 400]}
258        G2 = Geospatial_data(points, attributes)
259       
260#        g3 = geospatial_data2points_dictionary(G1)
261#        print 'g3=', g3
262       
263        G = G1 + G2
264
265        assert G.attributes.has_key('depth') 
266        assert G.attributes.keys(), ['depth']
267        assert allclose(G.attributes['depth'], [2, 4, 200, 400])
268        assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],
269                                              [5.0, 2.1], [3.0, 50.3]])
270    def test_add_with_geo (self):
271        """
272        Difference in Geo_reference resolved
273        """
274        points1 = [[1.0, 2.1], [3.0, 5.3]]
275        points2 = [[5.0, 6.1], [6.0, 3.3]]
276        attributes1 = [2, 4]
277        attributes2 = [5, 76]
278        geo_ref1= Geo_reference(55, 1.0, 2.0)
279        geo_ref2 = Geo_reference(zone=55,
280                                 xllcorner=0.1,
281                                 yllcorner=3.0,
282                                 datum='wgs84',
283                                 projection='UTM',
284                                 units='m')
285                               
286        G1 = Geospatial_data(points1, attributes1, geo_ref1)
287        G2 = Geospatial_data(points2, attributes2, geo_ref2)
288
289        #Check that absolute values are as expected
290        P1 = G1.get_data_points(absolute=True)
291        assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]])
292
293        P2 = G2.get_data_points(absolute=True)
294        assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]])       
295       
296        G = G1 + G2
297       
298        assert allclose(G.get_geo_reference().get_xllcorner(), 0.1)
299        assert allclose(G.get_geo_reference().get_yllcorner(), 2.0)
300
301        P = G.get_data_points(absolute=True)
302
303        P_relative = G.get_data_points(absolute=False)
304       
305        assert allclose(P_relative, P - [0.1, 2.0])
306
307        assert allclose(P, concatenate( (P1,P2) ))
308        assert allclose(P, [[2.0, 4.1], [4.0, 7.3],
309                            [5.1, 9.1], [6.1, 6.3]])
310       
311
312
313       
314
315    def test_add_with_geo_absolute (self):
316        """
317        Difference in Geo_reference resolved
318        """
319        points1 = array([[2.0, 4.1], [4.0, 7.3]])
320        points2 = array([[5.1, 9.1], [6.1, 6.3]])       
321        attributes1 = [2, 4]
322        attributes2 = [5, 76]
323        geo_ref1= Geo_reference(55, 1.0, 2.0)
324        geo_ref2 = Geo_reference(55, 2.0, 3.0)
325
326       
327                               
328        G1 = Geospatial_data(points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()],
329                             attributes1, geo_ref1)
330       
331        G2 = Geospatial_data(points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()],
332                             attributes2, geo_ref2)
333
334        #Check that absolute values are as expected
335        P1 = G1.get_data_points(absolute=True)
336        assert allclose(P1, points1)
337
338        P1 = G1.get_data_points(absolute=False)
339        assert allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()])       
340
341        P2 = G2.get_data_points(absolute=True)
342        assert allclose(P2, points2)
343
344        P2 = G2.get_data_points(absolute=False)
345        assert allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()])               
346       
347        G = G1 + G2
348       
349        assert allclose(G.get_geo_reference().get_xllcorner(), 1.0)
350        assert allclose(G.get_geo_reference().get_yllcorner(), 2.0)
351
352        P = G.get_data_points(absolute=True)
353
354        P_relative = G.get_data_points(absolute=False)
355       
356        assert allclose(P_relative, [[1.0, 2.1], [3.0, 5.3], [4.1, 7.1], [5.1, 4.3]])
357
358        assert allclose(P, concatenate( (points1,points2) ))
359                           
360       
361
362
363    def test_create_from_xya_file(self):
364        """Check that object can be created from a points file (.pts and .xya)
365        """
366
367        points = [[1.0, 2.1], [3.0, 5.3], [5.0, 6.1], [6.0, 3.3]]
368        attributes = [2, 4, 5, 76]
369        '''
370        # Use old pointsdict format
371        pointsdict = {'pointlist': points,
372                      'attributelist': {'att1': attributes,
373                                        'att2': array(attributes) + 1}}
374        '''
375        att_dict = {'att1': attributes,
376                    'att2': array(attributes) +1}
377                   
378        # Create points as an xya file
379        FN = 'test_points.xya'
380        G1 = Geospatial_data(points, att_dict)
381        G1.export_points_file(FN)
382#        G1.export_points_file(ofile)
383
384        #Create object from file
385        G = Geospatial_data(file_name = FN)
386       
387        assert allclose(G.get_data_points(), points)
388        assert allclose(G.get_attributes('att1'), attributes)
389        assert allclose(G.get_attributes('att2'), array(attributes) + 1)
390       
391        os.remove(FN)
392
393    def test_create_from_xya_file1(self):
394        """
395        Check that object can be created from an Absolute xya file
396        """
397
398        points = [[1.0, 2.1], [3.0, 5.3], [5.0, 6.1], [6.0, 3.3]]
399        attributes = [2, 4, 5, 76]
400
401        att_dict = {'att1': attributes,
402                    'att2': array(attributes) +1}
403
404        geo_ref = Geo_reference(56, 10, 5)
405                   
406        # Create points as an xya file
407        FN = 'test_points.xya'
408        G1 = Geospatial_data(points, att_dict, geo_ref)
409
410        G1.export_points_file(FN, absolute=True)
411
412        #Create object from file
413        G = Geospatial_data(file_name = FN)
414       
415        assert allclose(G.get_data_points(absolute=True), 
416                        G1.get_data_points(absolute=True))
417        assert allclose(G.get_attributes('att1'), attributes)
418        assert allclose(G.get_attributes('att2'), array(attributes) + 1)
419       
420        os.remove(FN)
421       
422    def test_loadxya(self):
423        """
424        comma delimited
425        """
426        fileName = tempfile.mktemp(".xya")
427        file = open(fileName,"w")
428        file.write("elevation  , speed \n\
4291.0, 0.0, 10.0, 0.0\n\
4300.0, 1.0, 0.0, 10.0\n\
4311.0, 0.0, 10.4, 40.0\n")
432        file.close()
433        results = Geospatial_data(fileName, delimiter=',')
434        os.remove(fileName)
435#        print 'data', results.get_data_points()
436        assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
437        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
438        assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
439
440    def test_loadxya2(self):
441        """
442        space delimited
443        """
444        import os
445       
446        fileName = tempfile.mktemp(".xya")
447        file = open(fileName,"w")
448        file.write("  elevation   speed \n\
4491.0 0.0 10.0 0.0\n\
4500.0 1.0 0.0 10.0\n\
4511.0 0.0 10.4 40.0\n")
452        file.close()
453
454        results = Geospatial_data(fileName, delimiter=' ')
455
456        os.remove(fileName)
457
458        assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
459        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
460        assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
461     
462    def test_loadxya3(self):
463        """
464        space delimited
465        """
466        import os
467       
468        fileName = tempfile.mktemp(".xya")
469        file = open(fileName,"w")
470        file.write("  elevation   speed \n\
4711.0 0.0 10.0 0.0\n\
4720.0 1.0 0.0 10.0\n\
4731.0 0.0 10.4 40.0\n\
474#geocrap\n\
47556\n\
47656.6\n\
4773\n")
478        file.close()
479
480        results = Geospatial_data(fileName, delimiter=' ')
481
482        os.remove(fileName)
483        assert allclose(results.get_data_points(absolute=False), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
484        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
485        assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
486
487    def BADtest_loadxya4(self):
488        """
489        comma delimited
490        """
491        fileName = tempfile.mktemp(".xya")
492        file = open(fileName,"w")
493        file.write("elevation  , speed \n\
4941.0, 0.0, splat, 0.0\n\
4950.0, 1.0, 0.0, 10.0\n\
4961.0, 0.0, 10.4, 40.0\n")
497        file.close()
498        results = Geospatial_data(fileName, delimiter=',')
499        os.remove(fileName)
500#        print 'data', results.get_data_points()
501        assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
502        assert allclose(results.get_attributes(attribute_name='elevation'), ["splat", 0.0, 10.4])
503        assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
504       
505    def test_read_write_points_file_bad2(self):
506        att_dict = {}
507        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
508        att_dict['elevation'] = array([10.0, 0.0, 10.4])
509        att_dict['brightness'] = array([10.0, 0.0, 10.4])
510        geo_reference=Geo_reference(56,1.9,1.9)
511       
512        G = Geospatial_data(pointlist, att_dict, geo_reference)
513       
514        try:
515            G.export_points_file("_???/yeah.xya")
516           
517        except IOError:
518            pass
519        else:
520            msg = 'bad points file extension did not raise error!'
521            raise msg
522#            self.failUnless(0 == 1,
523#                        'bad points file extension did not raise error!')
524                   
525    def test_loadxy_bad(self):
526        import os
527       
528        fileName = tempfile.mktemp(".xya")
529        file = open(fileName,"w")
530        file.write("  elevation   \n\
5311.0 0.0 10.0 0.0\n\
5320.0 1.0 0.0 10.0\n\
5331.0 0.0 10.4 40.0\n")
534        file.close()
535        #print fileName
536        try:
537            results = Geospatial_data(fileName, delimiter=' ')
538        except IOError:
539            pass
540        else:
541            msg = 'bad xya file did not raise error!'
542            raise msg
543#            self.failUnless(0 == 1,
544#                        'bad xya file did not raise error!')
545        os.remove(fileName)
546       
547    def test_loadxy_bad2(self):
548        import os
549       
550        fileName = tempfile.mktemp(".xya")
551        file = open(fileName,"w")
552        file.write("elevation\n\
5531.0 0.0 10.0 \n\
5540.0 1.0\n\
5551.0 \n")
556        file.close()
557        #print fileName
558        try:
559            results = Geospatial_data(fileName, delimiter=' ')
560        except IOError:
561            pass
562        else:
563            msg = 'bad xya file did not raise error!'
564            raise msg
565        os.remove(fileName)
566   
567    def test_loadxy_bad3(self):
568        """
569        specifying wrong delimiter
570        """
571        import os
572       
573        fileName = tempfile.mktemp(".xya")
574        file = open(fileName,"w")
575        file.write("  elevation  , speed \n\
5761.0, 0.0, 10.0, 0.0\n\
5770.0, 1.0, 0.0, 10.0\n\
5781.0, 0.0, 10.4, 40.0\n")
579        file.close()
580        try:
581            results = Geospatial_data(fileName, delimiter=' ')
582        except IOError:
583            pass
584        else:
585            msg = 'bad xya file did not raise error!'
586            raise msg
587        os.remove(fileName)
588     
589    def test_loadxy_bad4(self):
590        """
591         specifying wrong delimiter
592        """
593        import os
594        fileName = tempfile.mktemp(".xya")
595        file = open(fileName,"w")
596        file.write("  elevation   speed \n\
5971.0 0.0 10.0 0.0\n\
5980.0 1.0 0.0 10.0\n\
5991.0 0.0 10.4 40.0\n\
600#geocrap\n\
60156\n\
60256.6\n\
6033\n"
604)
605        file.close()
606        try:
607            results = Geospatial_data(fileName, delimiter=',')
608        except IOError:
609            pass
610        else:
611            msg = 'bad xya file did not raise error!'
612            raise msg
613
614        os.remove(fileName)
615
616    def test_loadxy_bad5(self):
617        """
618        specifying wrong delimiter
619        """
620        import os
621       
622        fileName = tempfile.mktemp(".xya")
623        file = open(fileName,"w")
624        file.write("  elevation   speed \n\
6251.0 0.0 10.0 0.0\n\
6260.0 1.0 0.0 10.0\n\
6271.0 0.0 10.4 40.0\n\
628#geocrap\n\
629crap")
630        file.close()
631        try:
632#            dict = import_points_file(fileName,delimiter=' ')
633#            results = Geospatial_data()
634            results = Geospatial_data(fileName, delimiter=' ', verbose=True)
635#            results.import_points_file(fileName, delimiter=' ')
636        except IOError:
637            pass
638        else:
639            msg = 'bad xya file did not raise error!'
640            raise msg
641
642#            self.failUnless(0 ==1,
643#                        'bad xya file did not raise error!')   
644        os.remove(fileName)             
645
646    def test_loadxy_bad_no_file_xya(self):
647        import os
648       
649        fileName = tempfile.mktemp(".xya")
650        try:
651            results = Geospatial_data(fileName, delimiter=' ')
652        except IOError:
653            pass
654        else:
655            msg = 'imaginary file did not raise error!'
656            raise msg
657
658#        except IOError:
659#            pass
660#        else:
661#            self.failUnless(0 == 1,
662#                        'imaginary file did not raise error!')
663
664                       
665  ###################### .XYA ##############################
666       
667    def test_export_xya_file(self):
668#        dict = {}
669        att_dict = {}
670        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
671        att_dict['elevation'] = array([10.0, 0.0, 10.4])
672        att_dict['brightness'] = array([10.0, 0.0, 10.4])
673#        dict['attributelist'] = att_dict
674        geo_reference=Geo_reference(56,1.9,1.9)
675       
676       
677        fileName = tempfile.mktemp(".xya")
678        G = Geospatial_data(pointlist, att_dict, geo_reference)
679        G.export_points_file(fileName, False)
680
681#        dict2 = import_points_file(fileName)
682        results = Geospatial_data(file_name = fileName)
683        #print "fileName",fileName
684        os.remove(fileName)
685       
686        assert allclose(results.get_data_points(absolute=False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
687        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
688        answer = [10.0, 0.0, 10.4]
689        assert allclose(results.get_attributes(attribute_name='brightness'), answer)
690        #print "dict2['geo_reference']",dict2['geo_reference']
691        self.failUnless(results.get_geo_reference() == geo_reference,
692                         'test_writepts failed. Test geo_reference')
693
694    def test_export_xya_file2(self):
695        """test absolute xya file
696        """
697        att_dict = {}
698        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
699        att_dict['elevation'] = array([10.0, 0.0, 10.4])
700        att_dict['brightness'] = array([10.0, 0.0, 10.4])
701       
702        fileName = tempfile.mktemp(".xya")
703        G = Geospatial_data(pointlist, att_dict)
704        G.export_points_file(fileName)
705        results = Geospatial_data(file_name = fileName)
706#        dict2 = import_points_file(fileName)
707        os.remove(fileName)
708       
709        assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
710        assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
711        answer = [10.0, 0.0, 10.4]
712        assert allclose(results.get_attributes('brightness'), answer)
713
714    def test_export_xya_file3(self):
715        """test absolute xya file with geo_ref
716        """
717        att_dict = {}
718        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
719        att_dict['elevation'] = array([10.0, 0.0, 10.4])
720        att_dict['brightness'] = array([10.0, 0.0, 10.4])
721        geo_reference=Geo_reference(56,1.9,1.9)
722       
723       
724        fileName = tempfile.mktemp(".xya")
725        G = Geospatial_data(pointlist, att_dict, geo_reference)
726       
727        G.export_points_file(fileName, absolute=True)
728       
729        results = Geospatial_data(file_name = fileName)
730        os.remove(fileName)
731
732        assert allclose(results.get_data_points(),
733                        [[2.9, 1.9],[1.9, 2.9],[2.9, 1.9]])
734        assert allclose(results.get_attributes(attribute_name='elevation'),
735                         [10.0, 0.0, 10.4])
736        answer = [10.0, 0.0, 10.4]
737        assert allclose(results.get_attributes(attribute_name='brightness'), answer)
738        self.failUnless(results.get_geo_reference() == geo_reference,
739                         'test_writepts failed. Test geo_reference')                         
740                       
741                       
742                       
743    def test_new_export_pts_file(self):
744        att_dict = {}
745        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
746        att_dict['elevation'] = array([10.1, 0.0, 10.4])
747        att_dict['brightness'] = array([10.0, 1.0, 10.4])
748       
749        fileName = tempfile.mktemp(".pts")
750       
751        G = Geospatial_data(pointlist, att_dict)
752       
753        G.export_points_file(fileName)
754
755        results = Geospatial_data(file_name = fileName)
756
757        os.remove(fileName)
758       
759        assert allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
760        assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
761        answer = [10.0, 1.0, 10.4]
762        assert allclose(results.get_attributes(attribute_name='brightness'), answer)
763
764    def test_new_export_absolute_pts_file(self):
765        att_dict = {}
766        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
767        att_dict['elevation'] = array([10.1, 0.0, 10.4])
768        att_dict['brightness'] = array([10.0, 1.0, 10.4])
769        geo_ref = Geo_reference(50, 25, 55)
770       
771        fileName = tempfile.mktemp(".pts")
772       
773        G = Geospatial_data(pointlist, att_dict, geo_ref)
774       
775        G.export_points_file(fileName, absolute=True)
776
777        results = Geospatial_data(file_name = fileName)
778
779        os.remove(fileName)
780       
781        assert allclose(results.get_data_points(), G.get_data_points(True))
782        assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])
783        answer = [10.0, 1.0, 10.4]
784        assert allclose(results.get_attributes(attribute_name='brightness'), answer)
785
786    def test_loadpts(self):
787       
788        from Scientific.IO.NetCDF import NetCDFFile
789
790        fileName = tempfile.mktemp(".pts")
791        # NetCDF file definition
792        outfile = NetCDFFile(fileName, 'w')
793       
794        # dimension definitions
795        outfile.createDimension('number_of_points', 3)   
796        outfile.createDimension('number_of_dimensions', 2) #This is 2d data
797   
798        # variable definitions
799        outfile.createVariable('points', Float, ('number_of_points',
800                                                 'number_of_dimensions'))
801        outfile.createVariable('elevation', Float, ('number_of_points',))
802   
803        # Get handles to the variables
804        points = outfile.variables['points']
805        elevation = outfile.variables['elevation']
806 
807        points[0, :] = [1.0,0.0]
808        elevation[0] = 10.0 
809        points[1, :] = [0.0,1.0]
810        elevation[1] = 0.0 
811        points[2, :] = [1.0,0.0]
812        elevation[2] = 10.4   
813
814        outfile.close()
815       
816        results = Geospatial_data(file_name = fileName)
817        os.remove(fileName)
818        answer =  [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]
819        assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
820        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
821       
822    def test_writepts(self):
823        att_dict = {}
824        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
825        att_dict['elevation'] = array([10.0, 0.0, 10.4])
826        att_dict['brightness'] = array([10.0, 0.0, 10.4])
827        geo_reference=Geo_reference(56,1.9,1.9)
828       
829        fileName = tempfile.mktemp(".pts")
830       
831        G = Geospatial_data(pointlist, att_dict, geo_reference)
832       
833        G.export_points_file(fileName, False)
834       
835        results = Geospatial_data(file_name = fileName)
836
837        os.remove(fileName)
838
839        assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
840        assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])
841        answer = [10.0, 0.0, 10.4]
842        assert allclose(results.get_attributes('brightness'), answer)
843
844       
845        self.failUnless(geo_reference == geo_reference,
846                         'test_writepts failed. Test geo_reference')
847       
848 ########################## BAD .PTS ##########################         
849
850    def test_load_bad_no_file_pts(self):
851        import os
852        import tempfile
853       
854        fileName = tempfile.mktemp(".pts")
855        #print fileName
856        try:
857            results = Geospatial_data(file_name = fileName)
858#            dict = import_points_file(fileName)
859        except IOError:
860            pass
861        else:
862            msg = 'imaginary file did not raise error!'
863            raise msg
864#            self.failUnless(0 == 1,
865#                        'imaginary file did not raise error!')
866
867
868    def test_create_from_pts_file(self):
869       
870        from Scientific.IO.NetCDF import NetCDFFile
871
872#        fileName = tempfile.mktemp(".pts")
873        FN = 'test_points.pts'
874        # NetCDF file definition
875        outfile = NetCDFFile(FN, 'w')
876       
877        # dimension definitions
878        outfile.createDimension('number_of_points', 3)   
879        outfile.createDimension('number_of_dimensions', 2) #This is 2d data
880   
881        # variable definitions
882        outfile.createVariable('points', Float, ('number_of_points',
883                                                 'number_of_dimensions'))
884        outfile.createVariable('elevation', Float, ('number_of_points',))
885   
886        # Get handles to the variables
887        points = outfile.variables['points']
888        elevation = outfile.variables['elevation']
889 
890        points[0, :] = [1.0,0.0]
891        elevation[0] = 10.0 
892        points[1, :] = [0.0,1.0]
893        elevation[1] = 0.0 
894        points[2, :] = [1.0,0.0]
895        elevation[2] = 10.4   
896
897        outfile.close()
898
899        G = Geospatial_data(file_name = FN)
900
901        assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
902        assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
903
904        assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
905        assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])
906        os.remove(FN)
907
908    def test_create_from_pts_file_with_geo(self):
909        """This test reveals if Geospatial data is correctly instantiated from a pts file.
910        """
911       
912        from Scientific.IO.NetCDF import NetCDFFile
913
914        FN = 'test_points.pts'
915        # NetCDF file definition
916        outfile = NetCDFFile(FN, 'w')
917
918        # Make up an arbitrary georef
919        xll = 0.1
920        yll = 20
921        geo_reference=Geo_reference(56, xll, yll)
922        geo_reference.write_NetCDF(outfile)
923
924        # dimension definitions
925        outfile.createDimension('number_of_points', 3)   
926        outfile.createDimension('number_of_dimensions', 2) #This is 2d data
927   
928        # variable definitions
929        outfile.createVariable('points', Float, ('number_of_points',
930                                                 'number_of_dimensions'))
931        outfile.createVariable('elevation', Float, ('number_of_points',))
932   
933        # Get handles to the variables
934        points = outfile.variables['points']
935        elevation = outfile.variables['elevation']
936
937        points[0, :] = [1.0,0.0]
938        elevation[0] = 10.0 
939        points[1, :] = [0.0,1.0]
940        elevation[1] = 0.0 
941        points[2, :] = [1.0,0.0]
942        elevation[2] = 10.4   
943
944        outfile.close()
945
946        G = Geospatial_data(file_name = FN)
947
948        assert allclose(G.get_geo_reference().get_xllcorner(), xll)
949        assert allclose(G.get_geo_reference().get_yllcorner(), yll)
950
951        assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],
952                                              [0.0+xll, 1.0+yll],
953                                              [1.0+xll, 0.0+yll]])
954       
955        assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])
956        os.remove(FN)
957
958       
959    def test_add_(self):
960        '''adds an xya and pts files, reads the files and adds them
961           checking results are correct
962        '''
963
964        # create files
965        att_dict1 = {}
966        pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
967        att_dict1['elevation'] = array([-10.0, 0.0, 10.4])
968        att_dict1['brightness'] = array([10.0, 0.0, 10.4])
969        geo_reference1 = Geo_reference(56, 2.0, 1.0)
970       
971        att_dict2 = {}
972        pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])
973        att_dict2['elevation'] = array([1.0, 15.0, 1.4])
974        att_dict2['brightness'] = array([14.0, 1.0, -12.4])
975        geo_reference2 = Geo_reference(56, 1.0, 2.0) 
976
977        G1 = Geospatial_data(pointlist1, att_dict1, geo_reference1)
978        G2 = Geospatial_data(pointlist2, att_dict2, geo_reference2)
979       
980        fileName1 = tempfile.mktemp(".xya")
981        fileName2 = tempfile.mktemp(".pts")
982
983        #makes files
984        G1.export_points_file(fileName1)
985        G2.export_points_file(fileName2)
986       
987        # add files
988       
989        G3 = Geospatial_data(file_name = fileName1)
990        G4 = Geospatial_data(file_name = fileName2)
991       
992        G = G3 + G4
993
994       
995        #read results
996#        print'res', G.get_data_points()
997#        print'res1', G.get_data_points(False)
998        assert allclose(G.get_data_points(),
999                        [[ 3.0, 1.0], [ 2.0, 2.0],
1000                         [ 3.0, 1.0], [ 3.0, 3.0],
1001                         [ 2.0, 4.0], [ 3.0, 3.0]])
1002                         
1003        assert allclose(G.get_attributes(attribute_name='elevation'),
1004                        [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4])
1005       
1006        answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4]
1007        assert allclose(G.get_attributes(attribute_name='brightness'), answer)
1008       
1009        self.failUnless(G.get_geo_reference() == geo_reference1,
1010                         'test_writepts failed. Test geo_reference')
1011                         
1012        os.remove(fileName1)
1013        os.remove(fileName2)
1014       
1015    def test_ensure_absolute(self):
1016        points = [[2.0, 0.0],[1.0, 1.0],
1017                         [2.0, 0.0],[2.0, 2.0],
1018                         [1.0, 3.0],[2.0, 2.0]]
1019        new_points = ensure_absolute(points)
1020       
1021        assert allclose(new_points, points)
1022
1023        points = array([[2.0, 0.0],[1.0, 1.0],
1024                         [2.0, 0.0],[2.0, 2.0],
1025                         [1.0, 3.0],[2.0, 2.0]])
1026        new_points = ensure_absolute(points)
1027       
1028        assert allclose(new_points, points)
1029       
1030        ab_points = array([[2.0, 0.0],[1.0, 1.0],
1031                         [2.0, 0.0],[2.0, 2.0],
1032                         [1.0, 3.0],[2.0, 2.0]])
1033       
1034        mesh_origin = (56, 290000, 618000) #zone, easting, northing
1035
1036        data_points = zeros((ab_points.shape), Float)
1037        #Shift datapoints according to new origins
1038        for k in range(len(ab_points)):
1039            data_points[k][0] = ab_points[k][0] - mesh_origin[1]
1040            data_points[k][1] = ab_points[k][1] - mesh_origin[2]
1041        #print "data_points",data_points     
1042        new_points = ensure_absolute(data_points,
1043                                             geo_reference=mesh_origin)
1044        #print "new_points",new_points
1045        #print "ab_points",ab_points
1046           
1047        assert allclose(new_points, ab_points)
1048
1049        geo = Geo_reference(56,67,-56)
1050
1051        data_points = geo.change_points_geo_ref(ab_points)   
1052        new_points = ensure_absolute(data_points,
1053                                             geo_reference=geo)
1054        #print "new_points",new_points
1055        #print "ab_points",ab_points
1056           
1057        assert allclose(new_points, ab_points)
1058
1059
1060        geo_reference = Geo_reference(56, 100, 200)
1061        ab_points = [[1.0, 2.1], [3.0, 5.3]]
1062        points = geo_reference.change_points_geo_ref(ab_points)
1063        attributes = [2, 4]
1064        #print "geo in points", points
1065        G = Geospatial_data(points, attributes,
1066                            geo_reference=geo_reference)
1067         
1068        new_points = ensure_absolute(G)
1069        #print "new_points",new_points
1070        #print "ab_points",ab_points
1071           
1072        assert allclose(new_points, ab_points)
1073
1074       
1075        fileName = tempfile.mktemp(".xya")
1076        file = open(fileName,"w")
1077        file.write("  elevation   speed \n\
10781.0 0.0 10.0 0.0\n\
10790.0 1.0 0.0 10.0\n\
10801.0 0.0 10.4 40.0\n\
1081#geocrap\n\
108256\n\
108310\n\
108420\n")
1085        file.close()
1086       
1087        ab_points = ensure_absolute(fileName)
1088        actual =  [[11, 20.0],[10.0, 21.0],[11.0, 20.0]]
1089        assert allclose(ab_points, actual)
1090        os.remove(fileName)
1091
1092       
1093    def test_ensure_geospatial(self):
1094        points = [[2.0, 0.0],[1.0, 1.0],
1095                         [2.0, 0.0],[2.0, 2.0],
1096                         [1.0, 3.0],[2.0, 2.0]]
1097        new_points = ensure_geospatial(points)
1098       
1099        assert allclose(new_points.get_data_points(absolute = True), points)
1100
1101        points = array([[2.0, 0.0],[1.0, 1.0],
1102                         [2.0, 0.0],[2.0, 2.0],
1103                         [1.0, 3.0],[2.0, 2.0]])
1104        new_points = ensure_geospatial(points)
1105       
1106        assert allclose(new_points.get_data_points(absolute = True), points)
1107       
1108        ab_points = array([[2.0, 0.0],[1.0, 1.0],
1109                         [2.0, 0.0],[2.0, 2.0],
1110                         [1.0, 3.0],[2.0, 2.0]])
1111       
1112        mesh_origin = (56, 290000, 618000) #zone, easting, northing
1113
1114        data_points = zeros((ab_points.shape), Float)
1115        #Shift datapoints according to new origins
1116        for k in range(len(ab_points)):
1117            data_points[k][0] = ab_points[k][0] - mesh_origin[1]
1118            data_points[k][1] = ab_points[k][1] - mesh_origin[2]
1119        #print "data_points",data_points     
1120        new_geospatial = ensure_geospatial(data_points,
1121                                             geo_reference=mesh_origin)
1122        new_points = new_geospatial.get_data_points(absolute=True)
1123        #print "new_points",new_points
1124        #print "ab_points",ab_points
1125           
1126        assert allclose(new_points, ab_points)
1127
1128        geo = Geo_reference(56,67,-56)
1129
1130        data_points = geo.change_points_geo_ref(ab_points)   
1131        new_geospatial = ensure_geospatial(data_points,
1132                                             geo_reference=geo)
1133        new_points = new_geospatial.get_data_points(absolute=True)
1134        #print "new_points",new_points
1135        #print "ab_points",ab_points
1136           
1137        assert allclose(new_points, ab_points)
1138
1139
1140        geo_reference = Geo_reference(56, 100, 200)
1141        ab_points = [[1.0, 2.1], [3.0, 5.3]]
1142        points = geo_reference.change_points_geo_ref(ab_points)
1143        attributes = [2, 4]
1144        #print "geo in points", points
1145        G = Geospatial_data(points, attributes,
1146                            geo_reference=geo_reference)
1147         
1148        new_geospatial  = ensure_geospatial(G)
1149        new_points = new_geospatial.get_data_points(absolute=True)
1150        #print "new_points",new_points
1151        #print "ab_points",ab_points
1152           
1153        assert allclose(new_points, ab_points)
1154       
1155    def test_isinstance(self):
1156
1157        import os
1158       
1159        fileName = tempfile.mktemp(".xya")
1160        file = open(fileName,"w")
1161        file.write("  elevation   speed \n\
11621.0 0.0 10.0 0.0\n\
11630.0 1.0 0.0 10.0\n\
11641.0 0.0 10.4 40.0\n\
1165#geocrap\n\
116656\n\
116756.6\n\
11683\n")
1169        file.close()
1170
1171        results = Geospatial_data(fileName)
1172        assert allclose(results.get_data_points(absolute=False), \
1173                        [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
1174        assert allclose(results.get_attributes(attribute_name='elevation'), \
1175                        [10.0, 0.0, 10.4])
1176        assert allclose(results.get_attributes(attribute_name='speed'), \
1177                        [0.0, 10.0, 40.0])
1178
1179        os.remove(fileName)
1180       
1181    def test_delimiter(self):
1182       
1183        try:
1184            G = Geospatial_data(delimiter=',')
1185#            results = Geospatial_data(file_name = fileName)
1186#            dict = import_points_file(fileName)
1187        except ValueError:
1188            pass
1189        else:
1190            msg = 'Instance with No fileName but has a delimiter\
1191                  did not raise error!'
1192            raise msg
1193
1194    def test_no_constructors(self):
1195       
1196        try:
1197            G = Geospatial_data()
1198#            results = Geospatial_data(file_name = fileName)
1199#            dict = import_points_file(fileName)
1200        except ValueError:
1201            pass
1202        else:
1203            msg = 'Instance must have a filename or data points'
1204            raise msg       
1205
1206    def test_check_geo_reference(self):
1207        """
1208        checks geo reference details are OK. eg can be called '#geo reference'
1209        if not throws a clear error message
1210        """
1211        import os
1212        fileName = tempfile.mktemp(".xya")
1213        file = open(fileName,"w")
1214        file.write("  elevation  \n\
12151.0 0.0 10.0\n\
12160.0 1.0 0.0\n\
12171.0 0.0 10.4\n\
1218#ge oreference\n\
121956\n\
12201.1\n\
12211.0\n")
1222
1223        file.close()
1224        results = Geospatial_data(fileName)
1225        assert allclose(results.get_geo_reference().get_xllcorner(), 1.1)
1226        assert allclose(results.get_geo_reference().get_yllcorner(), 1.0)
1227
1228        os.remove(fileName)
1229       
1230        fileName = tempfile.mktemp(".xya")
1231        file = open(fileName,"w")
1232        file.write("  elevation  \n\
12331.0 0.0 10.0\n\
12340.0 1.0 0.0\n\
12351.0 0.0 10.4\n")
1236
1237        file.close()
1238        results = Geospatial_data(fileName)
1239       
1240        os.remove(fileName)
1241       
1242    def test_check_geo_reference1(self):
1243        """
1244        checks geo reference details are OK. eg can be called '#geo reference'
1245        if not throws a clear error message
1246        """
1247        import os
1248        fileName = tempfile.mktemp(".xya")
1249        file = open(fileName,"w")
1250        file.write("  elevation  \n\
12511.0 0.0 10.0\n\
12520.0 1.0 0.0\n\
12531.0 0.0 10.4\n\
1254#geo t t\n\
125556\n\
12561.1\n"
1257)
1258        file.close()
1259
1260        try:
1261            results = Geospatial_data(fileName, delimiter = " ")
1262        except IOError:
1263            pass
1264        else:
1265            msg = 'Geo reference data format is incorrect'
1266            raise msg       
1267
1268
1269        os.remove(fileName)
1270
1271
1272       
1273    def test_lat_long(self):
1274        lat_gong = degminsec2decimal_degrees(-34,30,0.)
1275        lon_gong = degminsec2decimal_degrees(150,55,0.)
1276       
1277        lat_2 = degminsec2decimal_degrees(-34,00,0.)
1278        lon_2 = degminsec2decimal_degrees(150,00,0.)
1279       
1280        lats = [lat_gong, lat_2]
1281        longs = [lon_gong, lon_2]
1282        gsd = Geospatial_data(latitudes=lats, longitudes=longs)
1283
1284        points = gsd.get_data_points(absolute=True)
1285       
1286        assert allclose(points[0][0], 308728.009)
1287        assert allclose(points[0][1], 6180432.601)
1288        assert allclose(points[1][0],  222908.705)
1289        assert allclose(points[1][1], 6233785.284)
1290        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
1291                        'Bad zone error!')
1292       
1293        try:
1294            results = Geospatial_data(latitudes=lats)
1295        except ValueError:
1296            pass
1297        else:
1298            self.failUnless(0 ==1,  'Error not thrown error!')
1299        try:
1300            results = Geospatial_data(latitudes=lats)
1301        except ValueError:
1302            pass
1303        else:
1304            self.failUnless(0 ==1,  'Error not thrown error!')
1305        try:
1306            results = Geospatial_data(longitudes=lats)
1307        except ValueError:
1308            pass
1309        else:
1310            self.failUnless(0 ==1, 'Error not thrown error!')
1311        try:
1312            results = Geospatial_data(latitudes=lats, longitudes=longs,
1313                                      geo_reference="p")
1314        except ValueError:
1315            pass
1316        else:
1317            self.failUnless(0 ==1,  'Error not thrown error!')
1318           
1319        try:
1320            results = Geospatial_data(latitudes=lats, longitudes=longs,
1321                                      data_points=12)
1322        except ValueError:
1323            pass
1324        else:
1325            self.failUnless(0 ==1,  'Error not thrown error!')
1326
1327    def test_lat_long2(self):
1328        lat_gong = degminsec2decimal_degrees(-34,30,0.)
1329        lon_gong = degminsec2decimal_degrees(150,55,0.)
1330       
1331        lat_2 = degminsec2decimal_degrees(-34,00,0.)
1332        lon_2 = degminsec2decimal_degrees(150,00,0.)
1333       
1334        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
1335        gsd = Geospatial_data(data_points=points, points_are_lats_longs=True)
1336
1337        points = gsd.get_data_points(absolute=True)
1338       
1339        assert allclose(points[0][0], 308728.009)
1340        assert allclose(points[0][1], 6180432.601)
1341        assert allclose(points[1][0],  222908.705)
1342        assert allclose(points[1][1], 6233785.284)
1343        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
1344                        'Bad zone error!')
1345
1346        try:
1347            results = Geospatial_data(points_are_lats_longs=True)
1348        except ValueError:
1349            pass
1350        else:
1351            self.failUnless(0 ==1,  'Error not thrown error!')
1352
1353    def test_len(self):
1354       
1355        points = [[1.0, 2.1], [3.0, 5.3]]
1356        G = Geospatial_data(points)
1357        self.failUnless(2 ==len(G),  'Len error!')
1358       
1359        points = [[1.0, 2.1]]
1360        G = Geospatial_data(points)
1361        self.failUnless(1 ==len(G),  'Len error!')
1362
1363        points = [[1.0, 2.1], [3.0, 5.3], [3.0, 5.3], [3.0, 5.3]]
1364        G = Geospatial_data(points)
1365        self.failUnless(4 ==len(G),  'Len error!')
1366         
1367if __name__ == "__main__":
1368
1369    #suite = unittest.makeSuite(Test_Geospatial_data, 'test_ensure_geospatial')
1370    suite = unittest.makeSuite(Test_Geospatial_data, 'test')
1371    runner = unittest.TextTestRunner()
1372    runner.run(suite)
1373
1374   
Note: See TracBrowser for help on using the repository browser.