Package upoints :: Module trigpoints :: Class Trigpoints
[hide private]
[frames] | no frames]

Class Trigpoints

   object --+        
            |        
         dict --+    
                |    
point.KeyedPoints --+
                    |
                   Trigpoints

Class for representing a group of Trigpoint objects

Since: 0.5.1

Instance Methods [hide private]
new empty dictionary

__init__(self, marker_file=None)
Initialise a new Trigpoints object
dict
import_locations(self, marker_file)
Import trigpoint database files

Inherited from point.KeyedPoints: __repr__, bearing, destination, distance, final_bearing, forward, inverse, midpoint, range, sun_events, sunrise, sunset, to_grid_locator

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __setitem__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, marker_file=None)
(Constructor)

 
Initialise a new Trigpoints object
Parameters:
  • points - Point objects to wrap
  • parse - Whether to attempt import of points
  • units - Unit type to be used for distances when parsing string locations
Returns:
new empty dictionary

Overrides: object.__init__

import_locations(self, marker_file)

 

Import trigpoint database files

import_locations() returns a dictionary with keys containing the trigpoint identifier, and values that are Trigpoint objects.

It expects trigpoint marker files in the format provided at alltrigs-wgs84.txt, which is the following format:

H  SOFTWARE NAME & VERSION
I  GPSU 4.04,
S SymbolSet=0
...
W,500936,N52.066035,W000.281449,    37.0,Broom Farm
W,501097,N52.010585,W000.173443,    97.0,Bygrave
W,505392,N51.910886,W000.186462,   136.0,Sish Lane

Any line not consisting of 6 comma separated fields will be ignored. The reader uses Python's csv module, so alternative whitespace formatting should have no effect. The above file processed by import_locations() will return the following dict object:

{500936: point.Point(52.066035, -0.281449, 37.0, "Broom Farm"),
 501097: point.Point(52.010585, -0.173443, 97.0, "Bygrave"),
 505392: point.Point(51.910886, -0.186462, 136.0, "Sish Lane")}
>>> marker_file = open("trigpoints")
>>> markers = Trigpoints(marker_file)
>>> for key, value in sorted(markers.items()):
...     print("%s - %s" % (key, value))
500936 - Broom Farm (52°03'57"N, 000°16'53"W alt 37m)
501097 - Bygrave (52°00'38"N, 000°10'24"W alt 97m)
505392 - Sish Lane (51°54'39"N, 000°11'11"W alt 136m)
>>> marker_file.seek(0)
>>> markers = Trigpoints(marker_file.readlines())
>>> markers = Trigpoints(open("southern_trigpoints"))
>>> print(markers[1])
FakeLand (48°07'23"S, 000°07'23"W alt 12m)
>>> markers = Trigpoints(open("broken_trigpoints"))
>>> for key, value in sorted(markers.items()):
...     print("%s - %s" % (key, value))
500968 - Brown Hill Nm  See The Heights (53°38'23"N, 001°39'34"W)
501414 - Cheriton Hill Nm  See Paddlesworth (51°06'03"N, 001°08'33"E)
Parameters:
  • marker_file (file, list or str) - Trigpoint marker data to read
Returns: dict
Named locations with Trigpoint objects
Raises:
  • ValueError - Invalid value for marker_file
Overrides: point.KeyedPoints.import_locations