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_transform_geom_with_z(geom):
"""Transforming a geom with Z succeeds"""
g2 = transform.transform_geom("epsg:4326", "epsg:3857", geom, precision=3)
for i in range(1, len(files) + 1):
if str(i) not in layer.keys():
layer[str(i)] = [0]
try:
if bbox:
try:
bbox = tuple(map(float, bbox.split(',')))
except ValueError:
bbox = json.loads(bbox)
for i, path in enumerate(files, 1):
for lyr in layer[str(i)]:
with fiona.open(path, layer=lyr) as src:
for i, feat in src.items(bbox=bbox):
if dst_crs or precision >= 0:
g = transform_geom(
src.crs, dst_crs, feat['geometry'],
antimeridian_cutting=True,
precision=precision)
feat['geometry'] = g
feat['bbox'] = fiona.bounds(g)
if use_rs:
click.echo(u'\u001e', nl=False)
click.echo(json.dumps(feat, **dump_kwds))
except Exception:
logger.exception("Exception caught during processing")
raise click.Abort()
def __antiMeridianCut(self, geom):
"""
Solving antimeridian problem.
"""
src_crs = '+proj=longlat +datum=WGS84 +no_defs'
dst_crs = '+proj=longlat +datum=WGS84 +no_defs'
am_offset = 360.0
line_t = transform_geom(src_crs, dst_crs, geom,
antimeridian_cutting=self.__antimeridian,
antimeridian_offset=am_offset,
precision=-1)
return line_t
def transformer(crs, feat):
tg = partial(transform_geom, crs, 'EPSG:4326',
antimeridian_cutting=True, precision=precision)
feat['geometry'] = tg(feat['geometry'])
return feat
def _reproject_geom(geometry, src_crs, dst_crs):
if geometry.is_empty:
return geometry
else:
out_geom = to_shape(
transform_geom(
src_crs.to_dict(),
dst_crs.to_dict(),
mapping(geometry),
antimeridian_cutting=antimeridian_cutting
)
)
return _repair(out_geom) if validity_check else out_geom
def load(ctx, output, driver, src_crs, dst_crs, features, layer):
"""Load features from JSON to a file in another format.
The input is a GeoJSON feature collection or optionally a sequence of
GeoJSON feature objects.
"""
logger = logging.getLogger(__name__)
dst_crs = dst_crs or src_crs
if src_crs and dst_crs and src_crs != dst_crs:
transformer = partial(transform_geom, src_crs, dst_crs,
antimeridian_cutting=True, precision=-1)
else:
def transformer(x):
return x
def feature_gen():
for feat in features:
feat['geometry'] = transformer(feat['geometry'])
yield feat
try:
source = feature_gen()
# Use schema of first feature as a template.
# TODO: schema specified on command line?
first = next(source)