gnome.utilities.file_tools.haz_files

A module that contains various functions for reading and writing assorted HAZMAT file formats.

Some of these require the point in polygon code that is in the TAP check_receptors extension module. I should put that in another library.

Module Contents

Classes

BNAData

Class to store the full set of data in a BNA file

Functions

ReadDOGSFile(filename)

WriteDOGSFiles(filename, Coords, Depths[, Units])

ReadVerdatFile(filename)

This function reads a DOGS style verdat file

WriteVerdatFile(filename, PointData, Boundaries)

This function writes a verdata file, of the "DOGS" type.

GetNextBNAPolygon(f[, dtype])

Utility function that returns the next polygon from a BNA file

WriteBNA(filename, polyset)

Writes a BNA file to filename

ReadBNA(filename[, polytype, dtype])

Read a bna file.

Attributes

FILESCANNER

gnome.utilities.file_tools.haz_files.FILESCANNER = False
exception gnome.utilities.file_tools.haz_files.FileToolsException

Bases: Exception

The base class for all exceptions in the FileTools module

Initialize self. See help(type(self)) for accurate signature.

exception gnome.utilities.file_tools.haz_files.BnaError

Bases: FileToolsException

The base class for all exceptions in the FileTools module

Initialize self. See help(type(self)) for accurate signature.

class gnome.utilities.file_tools.haz_files.BNAData(PointsData=None, Names=None, Types=None, Filename=None)

Class to store the full set of data in a BNA file

Parameters:
  • PointsData – A sequence of numpy Nx2 arrays of the points (x,y) i.e. long,lat

  • Names – A sequence of stings for the names of the polygons

  • Types – A sequence of strings for the types of the polygons.

__getitem__(index)
__len__()
__str__()

Return str(self).

Save(filename=None)
gnome.utilities.file_tools.haz_files.ReadDOGSFile(filename)
gnome.utilities.file_tools.haz_files.WriteDOGSFiles(filename, Coords, Depths, Units='meters')
gnome.utilities.file_tools.haz_files.ReadVerdatFile(filename)

This function reads a DOGS style verdat file

The output is zero-index based, rather than 1-index based as it is in the file.

## fixme – this doesn’t keep the units if they are there in the header

gnome.utilities.file_tools.haz_files.WriteVerdatFile(filename, PointData, Boundaries)

This function writes a verdata file, of the “DOGS” type.

The data passed in must be Verdat legal, and is zero-index based.

gnome.utilities.file_tools.haz_files.GetNextBNAPolygon(f, dtype=np.float64)

Utility function that returns the next polygon from a BNA file

returns: (points, poly_type, name, sname) where:

points: Nx2numpy array of floats with the points poly_type: one of “point”, “line”, “poly” name: name defined in the BNA sname: secondary name defined in the BNA

NOTE: It is the BNA standard to duplicate the first and last points.

In that case, the duplicated last point is removed.

“holes” in polygons are not supported in this code.

See:

http://www.softwright.com/faq/support/boundary_file_bna_format.html

NOTE: This code doesn’t allow extra spaces around the commas in the

header line. If there are no commas allowed in the name, it would be easier to simply split on the commas (or march through the line looking for the quotes – regex?)

gnome.utilities.file_tools.haz_files.WriteBNA(filename, polyset)

Writes a BNA file to filename

polyset must be a A geometry.polygons.PolygonSet object,

with metadata- (poly_type, name, secondary name)

(such as returned by ReadBNA)

gnome.utilities.file_tools.haz_files.ReadBNA(filename, polytype='list', dtype=np.float64)

Read a bna file.

Results are returned as one of: - “list”: A list of tuples:

(points, poly_type, name, secondary name)

  • “PolygonSet”: A geometry.polygons.PolygonSet object,

    with metadata- (poly_type, name, secondary name)

  • “BNADataClass”: A BNAData class object – this may be broken now!

The dtype parameter specifies what numpy data type you want the points data in – it defaults to float (C double)