Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bbox2wktpolygon(bbox, expected):
result = util.bbox2wktpolygon(bbox)
assert result == expected
_set(
context,
recobj,
'pycsw:AnyText',
util.get_anytext([
md.contents[layer].title,
md.contents[layer].abstract,
','.join(keywords)
])
)
bbox = md.contents[layer].boundingBoxWGS84
if bbox is not None:
tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3])
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
_set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326')
_set(context, recobj, 'pycsw:DistanceUOM', 'degrees')
else:
bbox = md.contents[layer].boundingBox
if bbox:
tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3])
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
_set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \
bbox[-1].split(':')[1])
params = {
'service': 'WMTS',
'version': '1.0.0',
'request': 'GetTile',
'layer': md.contents[layer].name,
md.contents[layer].abstract,
','.join(md.contents[layer].keywords)
])
)
bbox = md.contents[layer].boundingBoxWGS84
if bbox is not None:
tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3])
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
_set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326')
_set(context, recobj, 'pycsw:DistanceUOM', 'degrees')
else:
bbox = md.contents[layer].boundingBox
if bbox:
tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3])
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
_set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \
bbox[-1].split(':')[1])
times = md.contents[layer].timepositions
if times is not None: # get temporal extent
time_begin = time_end = None
if len(times) == 1 and len(times[0].split('/')) > 1:
time_envelope = times[0].split('/')
time_begin = time_envelope[0]
time_end = time_envelope[1]
elif len(times) > 1: # get first/last
time_begin = times[0]
time_end = times[-1]
if all([time_begin is not None, time_end is not None]):
_set(context, recobj, 'pycsw:TempExtent_begin', time_begin)
_set(context, recobj, 'pycsw:TempExtent_end', time_end)
for ref in md.references:
tmp = ',,%s,%s' % (ref['scheme'], ref['url'])
links.append(tmp)
for uri in md.uris:
tmp = '%s,%s,%s,%s' % \
(uri['name'], uri['description'], uri['protocol'], uri['url'])
links.append(tmp)
if len(links) > 0:
_set(context, recobj, 'pycsw:Links', '^'.join(links))
if bbox is not None:
try:
tmp = '%s,%s,%s,%s' % (bbox.minx, bbox.miny, bbox.maxx, bbox.maxy)
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
except: # coordinates are corrupted, do not include
_set(context, recobj, 'pycsw:BoundingBox', None)
else:
_set(context, recobj, 'pycsw:BoundingBox', None)
return recobj
for link in md.idinfo.citation.citeinfo['onlink']:
tmp = ',,,%s' % link
links.append(tmp)
if hasattr(md, 'distinfo') and hasattr(md.distinfo, 'stdorder'):
for link in md.distinfo.stdorder['digform']:
tmp = ',%s,,%s' % (link['name'], link['url'])
links.append(tmp)
if len(links) > 0:
_set(context, recobj, 'pycsw:Links', '^'.join(links))
if bbox is not None:
try:
tmp = '%s,%s,%s,%s' % (bbox.minx, bbox.miny, bbox.maxx, bbox.maxy)
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
except: # coordinates are corrupted, do not include
_set(context, recobj, 'pycsw:BoundingBox', None)
else:
_set(context, recobj, 'pycsw:BoundingBox', None)
return recobj
for link in md.idinfo.citation.citeinfo['onlink']:
tmp = ',,,%s' % link
links.append(tmp)
if hasattr(md, 'distinfo') and hasattr(md.distinfo, 'stdorder'):
for link in md.distinfo.stdorder['digform']:
tmp = ',%s,,%s' % (link['name'], link['url'])
links.append(tmp)
if len(links) > 0:
_set(context, recobj, 'pycsw:Links', '^'.join(links))
if bbox is not None:
try:
tmp = '%s,%s,%s,%s' % (bbox.minx, bbox.miny, bbox.maxx, bbox.maxy)
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
except: # coordinates are corrupted, do not include
_set(context, recobj, 'pycsw:BoundingBox', None)
else:
_set(context, recobj, 'pycsw:BoundingBox', None)
return recobj
for ref in md.references:
tmp = ',,%s,%s' % (ref['scheme'], ref['url'])
links.append(tmp)
for uri in md.uris:
tmp = '%s,%s,%s,%s' % \
(uri['name'], uri['description'], uri['protocol'], uri['url'])
links.append(tmp)
if len(links) > 0:
_set(context, recobj, 'pycsw:Links', '^'.join(links))
if bbox is not None:
try:
tmp = '%s,%s,%s,%s' % (bbox.minx, bbox.miny, bbox.maxx, bbox.maxy)
_set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
except: # coordinates are corrupted, do not include
_set(context, recobj, 'pycsw:BoundingBox', None)
else:
_set(context, recobj, 'pycsw:BoundingBox', None)
return recobj
A sequence of strings containing Well-Known Text representations of
polygons
Returns
-------
str
Well-Known Text representation of the aggregated bounding box for
all the input polygons
"""
try:
multi_pol = MultiPolygon(
[loads(bbox) for bbox in bboxs]
)
bstr = ",".join(["{0:.2f}".format(b) for b in multi_pol.bounds])
return util.bbox2wktpolygon(bstr)
except Exception as err:
raise RuntimeError('Cannot aggregate polygons: %s' % str(err))
_set(context, serviceobj, 'pycsw:Abstract', md.identification.abstract)
_set(context, serviceobj, 'pycsw:Keywords', ','.join(md.identification.keywords))
_set(context, serviceobj, 'pycsw:Creator', md.provider.contact.name)
_set(context, serviceobj, 'pycsw:Publisher', md.provider.name)
_set(context, serviceobj, 'pycsw:Contributor', md.provider.contact.name)
_set(context, serviceobj, 'pycsw:OrganizationName', md.provider.contact.name)
_set(context, serviceobj, 'pycsw:AccessConstraints', md.identification.accessconstraints)
_set(context, serviceobj, 'pycsw:OtherConstraints', md.identification.fees)
_set(context, serviceobj, 'pycsw:Source', record)
_set(context, serviceobj, 'pycsw:Format', md.identification.type)
for c in md.contents:
if md.contents[c].parent is None:
bbox = md.contents[c].boundingBoxWGS84
tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3])
_set(context, serviceobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp))
break
_set(context, serviceobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326')
_set(context, serviceobj, 'pycsw:DistanceUOM', 'degrees')
_set(context, serviceobj, 'pycsw:ServiceType', 'OGC:WMTS')
_set(context, serviceobj, 'pycsw:ServiceTypeVersion', md.identification.version)
_set(context, serviceobj, 'pycsw:Operation', ','.join([d.name for d in md.operations]))
_set(context, serviceobj, 'pycsw:OperatesOn', ','.join(list(md.contents)))
_set(context, serviceobj, 'pycsw:CouplingType', 'tight')
links = [
'%s,OGC-WMTS Web Map Service,OGC:WMTS,%s' % (identifier, md.url),
]
_set(context, serviceobj, 'pycsw:Links', '^'.join(links))
_set(context, serviceobj, 'pycsw:XML', caps2iso(serviceobj, md, context))