Index: /inundation/geospatial_data/geospatial_data.py
===================================================================
--- /inundation/geospatial_data/geospatial_data.py	(revision 2697)
+++ /inundation/geospatial_data/geospatial_data.py	(revision 2698)
@@ -20,9 +20,9 @@
                  geo_reference = None,
                  default_attribute_name = None,
-                 file_name = None,
-                 absolute = True):
-
-        
-        """
+                 file_name = None):#,
+#                 absolute = True):
+
+        
+        '''
         Create instance from data points and associated attributes
 
@@ -50,10 +50,41 @@
         have dimensions "points" etc.
         xya file is a CVS file with lats(x), longs(y) and elevation(a). 
-        first line must be attribute name eg elevation  
-        
-        absolute: Return data points that are absolute or relative to
-        to a xll and yll in a zone
-        
-        """
+        first line must be attribute name eg elevation 
+        
+        The format for a .xya file is:
+            1st line:     [attribute names]
+            other lines:  x y [attributes]
+
+            for example:
+            elevation, friction
+            0.6, 0.7, 4.9, 0.3
+            1.9, 2.8, 5, 0.3
+            2.7, 2.4, 5.2, 0.3
+
+        The first two columns are always implicitly assumed to be x, y coordinates.
+        Use the same delimiter for the attribute names and the data
+
+        An xya file can optionally end with
+            #geo reference
+            56
+            466600.0
+            8644444.0
+
+        When the 1st # is the zone,
+        2nd # the xllcorner and 
+        3rd # the yllcorner
+        
+        The format for a Points dictionary is:
+
+          ['pointlist'] a 2 column array describing points. 1st column x, 2nd column y.
+          ['attributelist'], a dictionary of 1D arrays, representing attribute values
+          at the point.  The dictionary key is the attribute header.
+          ['geo_reference'] a Geo_refernece object. Use if the point information
+            is relative. This is optional.
+            eg
+            dic['pointlist'] = [[1.0,2.0],[3.0,5.0]]
+            dic['attributelist']['elevation'] = [[7.0,5.0]
+          
+        '''
         
 
@@ -61,9 +92,8 @@
             self.file_name = None
             self.check_data_points(data_points)
-
             self.set_attributes(attributes)
             self.set_geo_reference(geo_reference)
             self.set_default_attribute_name(default_attribute_name)
-            self.set_absolute(absolute)
+#            self.set_absolute(absolute)
         
         else:
@@ -156,5 +186,5 @@
                 self.file_name = file_name
                 print 'file name from set', self.file_name
-    
+    '''    
     def set_absolute(self, absolute = True):
         if absolute is False:
@@ -162,17 +192,5 @@
         else:
             self.absolute = True
-    
-    '''
-    def set_self_from_file(self, file_name = None):
-        # check if file_name is a string and also that the file exists
-        if file_name is None:
-            self.file_name = None
-
-        else:    
-            self.file_name = file_name
-            self = self.import_points_file(file_name)
-        return self
-        '''    
-
+    '''    
     def get_geo_reference(self):
         return self.geo_reference
@@ -292,6 +310,5 @@
         return Geospatial_data(new_points,
                                new_attributes,
-                               new_geo_ref,
-                               absolute = False)
+                               new_geo_ref)
 
 
@@ -415,21 +432,31 @@
 #        return all_data
     
-    def new_export_points_file(self, ofile):
+    def export_points_file(self, ofile, absolute=False):
+        
         """
         write a points file, ofile, as a text (.xya) or binary (.pts) file
-    
         ofile is the file name, including the extension
-    
         The point_dict is defined at the top of this file.
         """
+    
         #this was done for all keys in the mesh file.
         #if not mesh_dict.has_key('points'):
         #    mesh_dict['points'] = []
+            
         if (ofile[-4:] == ".xya"):
-            _new_write_xya_file(ofile, self.get_data_points(self.absolute), 
+            if absolute is True:         
+                _write_xya_file(ofile, self.get_data_points(absolute), 
+                                   self.get_all_attributes())
+            else:
+                _write_xya_file(ofile, self.get_data_points(absolute), 
                                    self.get_all_attributes(),
                                    self.get_geo_reference())
+                                    
         elif (ofile[-4:] == ".pts"):
-            _new_write_pts_file(ofile, self.get_data_points(self.absolute), 
+            if absolute is True:
+                _write_pts_file(ofile, self.get_data_points(absolute), 
+                                   self.get_all_attributes())
+            else:
+                _write_pts_file(ofile, self.get_data_points(absolute), 
                                    self.get_all_attributes(),
                                    self.get_geo_reference())
@@ -732,5 +759,5 @@
 
 
-def _new_write_pts_file(file_name, write_data_points,
+def _write_pts_file(file_name, write_data_points,
                                    write_attributes, 
                                    write_geo_reference = None):
@@ -782,5 +809,5 @@
 
 
-def _new_write_xya_file( file_name, write_data_points,
+def _write_xya_file( file_name, write_data_points,
                                     write_attributes, 
                                     write_geo_reference = None, 
@@ -986,5 +1013,5 @@
 #    G_points_dict = geospatial_data2points_dictionary(G)
 
-    G.new_export_points_file(results_file)
+    G.export_points_file(results_file)
     
     
Index: /inundation/geospatial_data/test_geospatial_data.py
===================================================================
--- /inundation/geospatial_data/test_geospatial_data.py	(revision 2697)
+++ /inundation/geospatial_data/test_geospatial_data.py	(revision 2698)
@@ -313,6 +313,6 @@
         FN = 'test_points.xya'
         G1 = Geospatial_data(points, att_dict)
-        G1.new_export_points_file(FN)
-#        G1.new_export_points_file(ofile)
+        G1.export_points_file(FN)
+#        G1.export_points_file(ofile)
 
         #Create object from file
@@ -320,4 +320,33 @@
         
         assert allclose(G.get_data_points(), points)
+        assert allclose(G.get_attributes('att1'), attributes)
+        assert allclose(G.get_attributes('att2'), array(attributes) + 1)
+        
+        os.remove(FN)
+
+    def test_create_from_xya_file1(self):
+        """
+        Check that object can be created from an Absolute xya file
+        """
+
+        points = [[1.0, 2.1], [3.0, 5.3], [5.0, 6.1], [6.0, 3.3]]
+        attributes = [2, 4, 5, 76]
+
+        att_dict = {'att1': attributes,
+                    'att2': array(attributes) +1}
+
+        geo_ref = Geo_reference(56, 10, 5)
+                    
+        # Create points as an xya file 
+        FN = 'test_points.xya'
+        G1 = Geospatial_data(points, att_dict, geo_ref)
+
+        G1.export_points_file(FN, absolute = True)
+
+        #Create object from file
+        G = Geospatial_data(file_name = FN)
+        
+        assert allclose(G.get_data_points(absolute = True), 
+                        G1.get_data_points(absolute = True))
         assert allclose(G.get_attributes('att1'), attributes)
         assert allclose(G.get_attributes('att2'), array(attributes) + 1)
@@ -414,6 +443,5 @@
         
         try:
-#            export_points_file("_???/yeah.xya",dict)
-            G.new_export_points_file("_???/yeah.xya")
+            G.export_points_file("_???/yeah.xya")
             
         except IOError:
@@ -581,6 +609,6 @@
         
         fileName = tempfile.mktemp(".xya")
-        G = Geospatial_data( pointlist, att_dict, geo_reference, absolute = False)
-        G.new_export_points_file(fileName)
+        G = Geospatial_data(pointlist, att_dict, geo_reference)
+        G.export_points_file(fileName)
         dict2 = import_points_file(fileName)
         #print "fileName",fileName 
@@ -597,18 +625,14 @@
 
     def test_export_xya_file2(self):
-#        dict = {}
         att_dict = {}
         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
         att_dict['elevation'] = array([10.0, 0.0, 10.4])
         att_dict['brightness'] = array([10.0, 0.0, 10.4])
-#        dict['attributelist'] = att_dict
         
         fileName = tempfile.mktemp(".xya")
         G = Geospatial_data(pointlist, att_dict)
-        G.new_export_points_file(fileName)
+        G.export_points_file(fileName)
         dict2 = import_points_file(fileName)
-        #print "fileName",fileName 
-        os.remove(fileName)
-        #print "dict2",dict2 
+        os.remove(fileName)
         
         assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
@@ -617,25 +641,28 @@
         assert allclose(dict2['attributelist']['brightness'], answer)
 
-    def test_new_export_xya_file2(self):
-        dict = {}
+    def test_export_xya_file2(self):
         att_dict = {}
         pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
-        att_dict['elevation'] = array([10.1, 0.0, 10.4])
-        att_dict['brightness'] = array([10.0, 1.0, 10.4])
-        
-        fileName = tempfile.mktemp(".xya")
-        
-        G = Geospatial_data(pointlist, att_dict)
-        
-        G.new_export_points_file(fileName)
-
+        att_dict['elevation'] = array([10.0, 0.0, 10.4])
+        att_dict['brightness'] = array([10.0, 0.0, 10.4])
+        geo_reference = Geo_reference(56,1.9,1.9)
+        
+        
+        fileName = tempfile.mktemp(".xya")
+        G = Geospatial_data(pointlist, att_dict, geo_reference)
+        G.export_points_file(fileName, absolute=True)
         dict2 = import_points_file(fileName)
-
-        os.remove(fileName)
-        
-        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
-        assert allclose(dict2['attributelist']['elevation'], [10.1, 0.0, 10.4])
-        answer = [10.0, 1.0, 10.4]
+        #print "fileName",fileName 
+        os.remove(fileName)
+        #print "dict2",dict2 
+        
+#        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
+        assert allclose(dict2['pointlist'],[[2.9, 1.9],[1.9, 2.9],[2.9, 1.9]])
+        assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4])
+        answer = [10.0, 0.0, 10.4]
         assert allclose(dict2['attributelist']['brightness'], answer)
+#        print "dict2['geo_reference']",dict2['geo_reference'] 
+        self.failUnless(None == dict2['geo_reference'],
+                         'test_writepts failed. Test geo_reference')
 
     def test_new_export_pts_file(self):
@@ -649,5 +676,5 @@
         G = Geospatial_data(pointlist, att_dict)
         
-        G.new_export_points_file(fileName)
+        G.export_points_file(fileName)
 
         dict2 = import_points_file(fileName)
@@ -660,4 +687,26 @@
         assert allclose(dict2['attributelist']['brightness'], answer)
 
+    def test_new_export_absolute_pts_file(self):
+        att_dict = {}
+        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
+        att_dict['elevation'] = array([10.1, 0.0, 10.4])
+        att_dict['brightness'] = array([10.0, 1.0, 10.4])
+        geo_ref = Geo_reference(50, 25, 55)
+        
+        fileName = tempfile.mktemp(".pts")
+        
+        G = Geospatial_data(pointlist, att_dict, geo_ref)
+        
+        G.export_points_file(fileName, absolute=True)
+
+        dict2 = import_points_file(fileName)
+
+        os.remove(fileName)
+        
+#        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
+        assert allclose(dict2['pointlist'],G.get_data_points(True))
+        assert allclose(dict2['attributelist']['elevation'], [10.1, 0.0, 10.4])
+        answer = [10.0, 1.0, 10.4]
+        assert allclose(dict2['attributelist']['brightness'], answer)
 
     def test_loadpts(self):
@@ -710,7 +759,7 @@
         fileName = tempfile.mktemp(".pts")
         
-        G = Geospatial_data(pointlist, att_dict, geo_reference, absolute = False)
-        
-        G.new_export_points_file(fileName)
+        G = Geospatial_data(pointlist, att_dict, geo_reference)
+        
+        G.export_points_file(fileName)
         
         dict2 = import_points_file(fileName)
@@ -867,6 +916,6 @@
         fileName2 = tempfile.mktemp(".pts")
 
-#        G1.new_export_points_file(fileName1)
-#        G2.new_export_points_file(fileName2)
+#        G1.export_points_file(fileName1)
+#        G2.export_points_file(fileName2)
         
         results_file = 'resulting_points.pts'
@@ -876,5 +925,5 @@
         G = G1 + G2
         
-        G.new_export_points_file(results_file)
+        G.export_points_file(results_file)
 #        add_points_files(fileName1, fileName2, results_file )
         
