# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# Path: lib/metrics.py
# class CHaMPMetric(object):
# 
#     # This is the dictionary representation of the object
#     # in its null state.
#     TEMPLATE = {}
# 
#     def __init__(self, *args, **kwargs):
#         # First initialize our logger and our empty metrics
#         self.log = Logger(self.__module__)
#         self.metrics = deepcopy(self.TEMPLATE)
# 
#         # Now try a calculation
#         try:
#             self.calc(*args, **kwargs)
#         except (DataException, MissingException), e:
#             self.log.warning("Could not complete metric calculation")
#             self.metrics = deepcopy(self.TEMPLATE)
# 
#     def calc(self, *args, **kwargs):
#         """
#         Needs to be overloaded in the children
#         :return:
#         """
#         raise Exception("YOU MUST IMPLEMENT THIS")


import sys
    import argparse
    import logging
from os import path
from lib.shapefileloader import *
from lib.exception import DataException
from lib.metrics import CHaMPMetric
from copy import copy
            if straightLength == 0:
                raise DataException("Zero length centerline feature encountered")

            if 'Channel' not in aLine['fields']:
                raise DataException("Centerline 'Channel' field missing")

            if aLine['fields']['Channel'] is None:
                raise DataException("Centerline 'Channel' field contains no data")

            dMetrics[lineIndex] = {}
            dMetrics[lineIndex]['Type'] = aLine['fields']['Channel']
            dMetrics[lineIndex]['Length'] = curvedLength
            dMetrics[lineIndex]['Sinuosity'] = curvedLength / straightLength
            dMetrics[lineIndex]['StraightLength'] = straightLength

            lineIndex += 1

        return dMetrics


    def _CenterlineSummaryMetrics(self, dMetrics):
        """

        :param dMetrics:
        :return:
        """
        lMainParts = [x for x in dMetrics.itervalues() if x['Type'] == 'Main']
        lSideParts = [x for x in dMetrics.itervalues() if x['Type'] != 'Main']

        if len(lMainParts) < 1:

# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# Path: lib/metrics.py
# class CHaMPMetric(object):
# 
#     # This is the dictionary representation of the object
#     # in its null state.
#     TEMPLATE = {}
# 
#     def __init__(self, *args, **kwargs):
#         # First initialize our logger and our empty metrics
#         self.log = Logger(self.__module__)
#         self.metrics = deepcopy(self.TEMPLATE)
# 
#         # Now try a calculation
#         try:
#             self.calc(*args, **kwargs)
#         except (DataException, MissingException), e:
#             self.log.warning("Could not complete metric calculation")
#             self.metrics = deepcopy(self.TEMPLATE)
# 
#     def calc(self, *args, **kwargs):
#         """
#         Needs to be overloaded in the children
#         :return:
#         """
#         raise Exception("YOU MUST IMPLEMENT THIS")


# Path: tools/topometrics/methods/centerline.py
import sys
    import argparse
    import logging
from os import path
from lib.shapefileloader import *
from lib.exception import DataException
from lib.metrics import CHaMPMetric
from copy import copy

            if straightLength == 0:
                raise DataException("Zero length centerline feature encountered")

            if 'Channel' not in aLine['fields']:
                raise DataException("Centerline 'Channel' field missing")

            if aLine['fields']['Channel'] is None:
                raise DataException("Centerline 'Channel' field contains no data")

            dMetrics[lineIndex] = {}
            dMetrics[lineIndex]['Type'] = aLine['fields']['Channel']
            dMetrics[lineIndex]['Length'] = curvedLength
            dMetrics[lineIndex]['Sinuosity'] = curvedLength / straightLength
            dMetrics[lineIndex]['StraightLength'] = straightLength

            lineIndex += 1

        return dMetrics


    def _CenterlineSummaryMetrics(self, dMetrics):
        """

        :param dMetrics:
        :return:
        """
        lMainParts = [x for x in dMetrics.itervalues() if x['Type'] == 'Main']
        lSideParts = [x for x in dMetrics.itervalues() if x['Type'] != 'Main']

        if len(lMainParts) < 1:

            raise DataException("Zero number of mainstem channel parts.")