mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Remove older scripts.
This commit is contained in:
parent
a2b9a447db
commit
fa0e94a545
@ -1,120 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Copy a raster with various options."""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import rasterio
|
||||
|
||||
|
||||
def main():
|
||||
"""Copy from source to destination with new options"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Copy raster file with options")
|
||||
parser.add_argument(
|
||||
'source',
|
||||
metavar='SOURCE',
|
||||
help="Source file name")
|
||||
parser.add_argument(
|
||||
'destination',
|
||||
metavar='DESTINATION',
|
||||
help="Destination file name")
|
||||
# TODO: add a short option for the following.
|
||||
parser.add_argument(
|
||||
'--template-file',
|
||||
metavar='FILE',
|
||||
help="Use a georeferenced file as a template")
|
||||
parser.add_argument(
|
||||
'-z', '--lzw',
|
||||
action='store_true',
|
||||
help="Compress destination using LZW")
|
||||
parser.add_argument(
|
||||
'--interleave-band',
|
||||
action='store_true',
|
||||
help="Band rather than pixel interleaved")
|
||||
parser.add_argument(
|
||||
'-t', '--tiled',
|
||||
action='store_true',
|
||||
help="Tiled rather than striped TIFFs")
|
||||
parser.add_argument(
|
||||
'--block-height',
|
||||
metavar='HEIGHT',
|
||||
help="Tile or strip height")
|
||||
parser.add_argument(
|
||||
'--block-width',
|
||||
metavar='WIDTH',
|
||||
help="Tile width")
|
||||
parser.add_argument(
|
||||
'-v', '--verbose',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Increase verbosity")
|
||||
parser.add_argument(
|
||||
'-q', '--quiet',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Decrease verbosity")
|
||||
args = parser.parse_args()
|
||||
|
||||
verbosity = args.verbose - args.quiet
|
||||
log_level = max(10, 30 - 10*verbosity)
|
||||
logging.basicConfig(stream=sys.stderr, level=log_level)
|
||||
logger = logging.getLogger('rio_cp')
|
||||
|
||||
# TODO: quick check of filenames before we call main().
|
||||
|
||||
options = {}
|
||||
if args.interleave_band:
|
||||
options['interleave'] = 'band'
|
||||
if args.lzw:
|
||||
options['compress'] = 'LZW'
|
||||
if args.tiled:
|
||||
options['tiled'] = True
|
||||
if args.block_height:
|
||||
options['blockysize'] = args.block_height
|
||||
if args.block_width:
|
||||
options['blockxsize'] = args.block_width
|
||||
|
||||
# TODO: support other formats.
|
||||
options['driver'] = 'GTiff'
|
||||
|
||||
source = args.source
|
||||
destination = args.destination
|
||||
opts = options
|
||||
template=args.template_file,
|
||||
log = logger
|
||||
|
||||
with rasterio.drivers():
|
||||
|
||||
try:
|
||||
|
||||
with rasterio.open(source) as src:
|
||||
|
||||
# First, copy the opts to the destination's kwargs.
|
||||
kwargs = src.meta
|
||||
kwargs.update(opts)
|
||||
|
||||
# If there's a template file, overlay its georeferencing.
|
||||
if template is not None:
|
||||
with rasterio.open(template) as tmpl:
|
||||
kwargs['transform'] = tmpl.transform
|
||||
kwargs['crs'] = tmpl.crs
|
||||
|
||||
# Write to the destination.
|
||||
# TODO: use shortcut to source buffer.
|
||||
with rasterio.open(destination, 'w', **kwargs) as dst:
|
||||
for i in dst.indexes:
|
||||
dst.write_band(i, src.read_band(i))
|
||||
|
||||
except:
|
||||
log.exception("rio_cp failed, exception caught")
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Rasterio interactive dataset inspector"""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import pprint
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
import rasterio
|
||||
import rasterio.tool
|
||||
|
||||
|
||||
warnings.simplefilter('default')
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="rio_insp",
|
||||
description="Open a dataset and drop into an interactive interpreter")
|
||||
parser.add_argument(
|
||||
'src',
|
||||
metavar='FILE',
|
||||
help="Input dataset file name")
|
||||
parser.add_argument(
|
||||
'-m', '--mode',
|
||||
metavar='MODE',
|
||||
type=str,
|
||||
default='r',
|
||||
help="File mode ('r' or 'r+')")
|
||||
parser.add_argument(
|
||||
'--meta',
|
||||
action='store_true',
|
||||
help="Pretty print the dataset's meta properties and exit")
|
||||
parser.add_argument(
|
||||
'--tags',
|
||||
nargs='?',
|
||||
default=None,
|
||||
const='',
|
||||
type=str,
|
||||
help="Pretty print the dataset's tags and exit")
|
||||
parser.add_argument(
|
||||
'--indent',
|
||||
default=2,
|
||||
type=int,
|
||||
metavar='N',
|
||||
help="Indentation level for pretty printed output")
|
||||
parser.add_argument(
|
||||
'-v', '--verbose',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Increase verbosity")
|
||||
parser.add_argument(
|
||||
'-q', '--quiet',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Decrease verbosity")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
verbosity = args.verbose - args.quiet
|
||||
log_level = max(10, 30 - 10*verbosity)
|
||||
logging.basicConfig(stream=sys.stderr, level=log_level)
|
||||
logger = logging.getLogger('rio_insp')
|
||||
|
||||
try:
|
||||
with rasterio.drivers(CPL_DEBUG=verbosity>2):
|
||||
with rasterio.open(args.src, args.mode) as src:
|
||||
if args.meta:
|
||||
pprint.pprint(src.meta, indent=args.indent)
|
||||
elif args.tags is not None:
|
||||
if not args.tags:
|
||||
tag_ns = None
|
||||
else:
|
||||
tag_ns = args.tags
|
||||
pprint.pprint(src.tags(ns=tag_ns), indent=args.indent)
|
||||
else:
|
||||
rasterio.tool.main(
|
||||
"Rasterio %s Interactive Inspector (Python %s)\n"
|
||||
'Type "src.meta", "src.read_band(1)", or "help(src)" '
|
||||
'for more information.' % (
|
||||
rasterio.__version__,
|
||||
'.'.join(map(str, sys.version_info[:3]))),
|
||||
src)
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
logger.exception("Failed. Exception caught")
|
||||
sys.exit(1)
|
||||
|
||||
@ -1,102 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Warp a raster."""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from pyproj import Proj, transform
|
||||
|
||||
import rasterio
|
||||
|
||||
|
||||
def main():
|
||||
"""Copy from source to destination with new options"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Warp a raster file")
|
||||
parser.add_argument(
|
||||
'source',
|
||||
metavar='SOURCE',
|
||||
help="Source file name")
|
||||
parser.add_argument(
|
||||
'destination',
|
||||
metavar='DESTINATION',
|
||||
help="Destination file name")
|
||||
# TODO: add a short option for the following.
|
||||
parser.add_argument(
|
||||
'--template-file',
|
||||
metavar='FILE',
|
||||
help="Use a georeferenced file as a template")
|
||||
parser.add_argument(
|
||||
'--destination-crs',
|
||||
metavar='CRS',
|
||||
help="Destination coordinate reference system")
|
||||
parser.add_argument(
|
||||
'-v', '--verbose',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Increase verbosity")
|
||||
parser.add_argument(
|
||||
'-q', '--quiet',
|
||||
action='count',
|
||||
default=0,
|
||||
help="Decrease verbosity")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
verbosity = args.v - args.q
|
||||
logging.basicConfig(stream=sys.stderr, level=(30 - 10*verbosity))
|
||||
logger = logging.getLogger('rasterio')
|
||||
|
||||
# TODO: quick check of filenames before we call main().
|
||||
|
||||
# TODO: support other formats.
|
||||
options['driver'] = 'GTiff'
|
||||
|
||||
source = args.source
|
||||
destination = args.destination
|
||||
dest_crs = args.destination_crs
|
||||
template=args.template_file
|
||||
log=logger
|
||||
|
||||
with rasterio.drivers():
|
||||
|
||||
try:
|
||||
|
||||
with rasterio.open(source) as src:
|
||||
|
||||
# First, copy the opts to the destination's kwargs.
|
||||
kwargs = src.meta.copy()
|
||||
kwargs.update(opts)
|
||||
|
||||
# If there's a template file, overlay its georeferencing.
|
||||
if template is not None:
|
||||
with rasterio.open(template) as tmpl:
|
||||
kwargs['transform'] = tmpl.transform
|
||||
kwargs['crs'] = tmpl.crs
|
||||
|
||||
# Determine the output extent.
|
||||
minx, miny = src.bounds[:2]
|
||||
ulx, uly = transform(Proj(src.crs), Proj(dst.crs),
|
||||
minx, maxy)
|
||||
|
||||
dst_transform = [ulx, dest_res, 0.0, uly, 0.0, -dest_res]
|
||||
|
||||
|
||||
|
||||
# Write to the destination.
|
||||
# TODO: use shortcut to source buffer
|
||||
with rasterio.open(destination, 'w', **kwargs) as dst:
|
||||
for i in src.indexes:
|
||||
dst.write_band(i, src.read_band(i))
|
||||
|
||||
except:
|
||||
log.exception("rio_cp failed, exception caught")
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user