# Path: gips/core.py
# class SpatialExtent(object):
#     """ Description of spatial extent """
# 
#     @classmethod
#     def factory(cls, dataclass, site=None, key='', where='', tiles=None, pcov=0.0, ptile=0.0):
#         """ Create array of SpatialExtent instances """
#         if site is None and tiles is None:
#             # raise Exception('Site geometry and/or tile ids required')
#             tiles = dataclass.Asset.Repository.find_tiles()
#         extents = []
#         if site is None:
#             # tiles are spatial extent
#             for t in tiles:
#                 extents.append(cls(dataclass, tiles=[t], pcov=pcov, ptile=ptile))
#         else:
#             features = open_vector(site, key, where)
#             for f in features:
#                 extents.append(cls(dataclass, feature=f, tiles=tiles, pcov=pcov, ptile=ptile))
#         return extents
# 
#     def __init__(self, dataclass, feature=None, tiles=None, pcov=0.0, ptile=0.0):
#         """ Create spatial extent with a GeoFeature instance or list of tiles """
#         self.repo = dataclass.Asset.Repository
# 
#         # TODO - try and close this and only open on demand (make site property)
#         self.site = feature
# 
#         # default to all tiles if none provided
#         if tiles is None and feature is None:
#             tiles = self.repo.find_tiles()
# 
#         if feature is not None:
#             tiles = self.repo.vector2tiles(feature, pcov, ptile, tiles)
#             self.feature = (feature.Filename(), feature.LayerName(), feature.FID())
#             self.sitename = feature.Basename()
#         else:
#             tiles = {t: (1, 1) for t in tiles}
#             self.sitename = 'tiles'
#         self.coverage = tiles
# 
#     @property
#     def tiles(self):
#         """ List of tile ids """
#         return self.coverage.keys()
# 
#     @property
#     def available_dates(self):
#         """ Get list of all dates for these tiles """
#         dates = []
#         for t in self.tiles:
#             dates.extend(self.repo.find_dates(t))
#         return dates
# 
#     def print_tile_coverage(self):
#         """ Print tile coverage info """
#         if self.site is not None:
#             print Colors.BOLD + '\nTile Coverage'
#             print Colors.UNDER + '{:^8}{:>14}{:>14}'.format('Tile', '% Coverage', '% Tile Used') + Colors.OFF
#             for t in sorted(self.coverage):
#                 print "{:>8}{:>11.1f}%{:>11.1f}%".format(t, self.coverage[t][0] * 100, self.coverage[t][1] * 100)
# 
#     def __str__(self):
#         """ String representation of spatial extent """
#         return '%s: %s' % (self.sitename, ' '.join(self.tiles))
# 
# Path: gips/utils.py
# def open_vector(fname, key="", where=''):
#     """ Open vector or feature """
#     parts = fname.split(':')
#     if len(parts) == 1:
#         vector = GeoVector(fname)
#         vector.SetPrimaryKey(key)
#     else:
#         # or it is a database
#         if parts[0] not in settings().DATABASES.keys():
#             raise Exception("%s is not a valid database" % parts[0])
#         try:
#             db = settings().DATABASES[parts[0]]
#             filename = ("PG:dbname=%s host=%s port=%s user=%s password=%s" %
#                         (db['NAME'], db['HOST'], db['PORT'], db['USER'], db['PASSWORD']))
#             vector = GeoVector(filename, parts[1])
#             vector.SetPrimaryKey(key)
# 
#         except Exception, e:
#             VerboseOut(traceback.format_exc(), 4)
#     if where != '':
#         # return array of features
#         return vector.where(where)
#         features = []
#     else:
#         return vector


    from gips.data.cdl import cdlData as data
    from gips.data.cdl import CDLData as data
from gips.core import SpatialExtent
from gips.utils import open_vector
from shapely.wkt import loads
from timeit import Timer
#!/usr/bin/env python

try:
except:


extent = SpatialExtent.factory(data, 'Belknap.shp')


assert len(extent[0].tiles) == 1, ('Belknap is contained wholly NH tile, '
                                   'but vector2tiles says it is in {} tiles'
                                   .format(len(extent[0].tiles)))

t = 'NH.shp'
f = 'NHseacoast.shp'


aWKT = open_vector(t)[0].WKT()

# Path: gips/core.py
# class SpatialExtent(object):
#     """ Description of spatial extent """
# 
#     @classmethod
#     def factory(cls, dataclass, site=None, key='', where='', tiles=None, pcov=0.0, ptile=0.0):
#         """ Create array of SpatialExtent instances """
#         if site is None and tiles is None:
#             # raise Exception('Site geometry and/or tile ids required')
#             tiles = dataclass.Asset.Repository.find_tiles()
#         extents = []
#         if site is None:
#             # tiles are spatial extent
#             for t in tiles:
#                 extents.append(cls(dataclass, tiles=[t], pcov=pcov, ptile=ptile))
#         else:
#             features = open_vector(site, key, where)
#             for f in features:
#                 extents.append(cls(dataclass, feature=f, tiles=tiles, pcov=pcov, ptile=ptile))
#         return extents
# 
#     def __init__(self, dataclass, feature=None, tiles=None, pcov=0.0, ptile=0.0):
#         """ Create spatial extent with a GeoFeature instance or list of tiles """
#         self.repo = dataclass.Asset.Repository
# 
#         # TODO - try and close this and only open on demand (make site property)
#         self.site = feature
# 
#         # default to all tiles if none provided
#         if tiles is None and feature is None:
#             tiles = self.repo.find_tiles()
# 
#         if feature is not None:
#             tiles = self.repo.vector2tiles(feature, pcov, ptile, tiles)
#             self.feature = (feature.Filename(), feature.LayerName(), feature.FID())
#             self.sitename = feature.Basename()
#         else:
#             tiles = {t: (1, 1) for t in tiles}
#             self.sitename = 'tiles'
#         self.coverage = tiles
# 
#     @property
#     def tiles(self):
#         """ List of tile ids """
#         return self.coverage.keys()
# 
#     @property
#     def available_dates(self):
#         """ Get list of all dates for these tiles """
#         dates = []
#         for t in self.tiles:
#             dates.extend(self.repo.find_dates(t))
#         return dates
# 
#     def print_tile_coverage(self):
#         """ Print tile coverage info """
#         if self.site is not None:
#             print Colors.BOLD + '\nTile Coverage'
#             print Colors.UNDER + '{:^8}{:>14}{:>14}'.format('Tile', '% Coverage', '% Tile Used') + Colors.OFF
#             for t in sorted(self.coverage):
#                 print "{:>8}{:>11.1f}%{:>11.1f}%".format(t, self.coverage[t][0] * 100, self.coverage[t][1] * 100)
# 
#     def __str__(self):
#         """ String representation of spatial extent """
#         return '%s: %s' % (self.sitename, ' '.join(self.tiles))
# 
# Path: gips/utils.py
# def open_vector(fname, key="", where=''):
#     """ Open vector or feature """
#     parts = fname.split(':')
#     if len(parts) == 1:
#         vector = GeoVector(fname)
#         vector.SetPrimaryKey(key)
#     else:
#         # or it is a database
#         if parts[0] not in settings().DATABASES.keys():
#             raise Exception("%s is not a valid database" % parts[0])
#         try:
#             db = settings().DATABASES[parts[0]]
#             filename = ("PG:dbname=%s host=%s port=%s user=%s password=%s" %
#                         (db['NAME'], db['HOST'], db['PORT'], db['USER'], db['PASSWORD']))
#             vector = GeoVector(filename, parts[1])
#             vector.SetPrimaryKey(key)
# 
#         except Exception, e:
#             VerboseOut(traceback.format_exc(), 4)
#     if where != '':
#         # return array of features
#         return vector.where(where)
#         features = []
#     else:
#         return vector


# Path: gips/test/tile_geom.py
    from gips.data.cdl import cdlData as data
    from gips.data.cdl import CDLData as data
from gips.core import SpatialExtent
from gips.utils import open_vector
from shapely.wkt import loads
from timeit import Timer

#!/usr/bin/env python

try:
except:


extent = SpatialExtent.factory(data, 'Belknap.shp')


assert len(extent[0].tiles) == 1, ('Belknap is contained wholly NH tile, '
                                   'but vector2tiles says it is in {} tiles'
                                   .format(len(extent[0].tiles)))

t = 'NH.shp'
f = 'NHseacoast.shp'


aWKT = open_vector(t)[0].WKT()

bWKT = open_vector(f)[0].WKT()