# Path: tools/validation/classes/vector.py
# class CHaMP_Polygon(CHaMP_Vector):
# 
#     geomType = ["Polygon", "MultiPolygon"]
# 
#     def feat_min_area(self, minArea):
#         for feat in self.features:
#             if feat['geometry'].area < minArea:
#                 return False
#         return True
# 
#     def validate(self):
# 
#         results = super(CHaMP_Polygon, self).validate()
# 
#         validate_geomtype = ValidationResult(self.__class__.__name__, "GeometryType")
# 
#         if self.exists():
#             if len(self.features) > 0:
#                 feat = self.features[0] # Only Checking one feature right now
#                 if feat["geometry"].geom_type in self.geomType:
#                     validate_geomtype.pass_validation()
#                 else:
#                     validate_geomtype.error("Geometry Type (" + str(self.geomType) + ") is not correct Type (" + \
#                                                 str(feat["geometry"].geom_type) + ")")
#             else:
#                 validate_geomtype.status = "NotTested"
#                 validate_geomtype.message = "Geometry has no features"
# 
#         results.append(validate_geomtype.get_dict())
# 
#         return results


import argparse
import sys, traceback
from tools.validation.classes.vector import CHaMP_Polygon

def polyinsidepoly(inner, outer):

    for innerPoly in inner.features:
        results = []
        for outPoly in outer.features:
            buffered = outPoly['geometry'].buffer(0.001)
            results.append(buffered.contains(innerPoly['geometry']))

        if not any(results):
            return False

    return True

def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('testShapeFile', help='Path ShapeFile that must occur inside.', type=argparse.FileType('r'))
    parser.add_argument('outerShapeFile', help='Path to the outer ShapeFile that must contain the test.', type=argparse.FileType('r'))
    args = parser.parse_args()

    try:
        inner = CHaMP_Polygon('test', args.testShapeFile.name)

# Path: tools/validation/classes/vector.py
# class CHaMP_Polygon(CHaMP_Vector):
# 
#     geomType = ["Polygon", "MultiPolygon"]
# 
#     def feat_min_area(self, minArea):
#         for feat in self.features:
#             if feat['geometry'].area < minArea:
#                 return False
#         return True
# 
#     def validate(self):
# 
#         results = super(CHaMP_Polygon, self).validate()
# 
#         validate_geomtype = ValidationResult(self.__class__.__name__, "GeometryType")
# 
#         if self.exists():
#             if len(self.features) > 0:
#                 feat = self.features[0] # Only Checking one feature right now
#                 if feat["geometry"].geom_type in self.geomType:
#                     validate_geomtype.pass_validation()
#                 else:
#                     validate_geomtype.error("Geometry Type (" + str(self.geomType) + ") is not correct Type (" + \
#                                                 str(feat["geometry"].geom_type) + ")")
#             else:
#                 validate_geomtype.status = "NotTested"
#                 validate_geomtype.message = "Geometry has no features"
# 
#         results.append(validate_geomtype.get_dict())
# 
#         return results


# Path: test/test_polygons_inside_other_polygons.py
import argparse
import sys, traceback
from tools.validation.classes.vector import CHaMP_Polygon


def polyinsidepoly(inner, outer):

    for innerPoly in inner.features:
        results = []
        for outPoly in outer.features:
            buffered = outPoly['geometry'].buffer(0.001)
            results.append(buffered.contains(innerPoly['geometry']))

        if not any(results):
            return False

    return True

def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('testShapeFile', help='Path ShapeFile that must occur inside.', type=argparse.FileType('r'))
    parser.add_argument('outerShapeFile', help='Path to the outer ShapeFile that must contain the test.', type=argparse.FileType('r'))
    args = parser.parse_args()

    try:
        inner = CHaMP_Polygon('test', args.testShapeFile.name)

        outer = CHaMP_Polygon('outer', args.outerShapeFile.name)