├── joydivision ├── scripts │ ├── __init__.py │ └── cli.py └── __init__.py ├── tests ├── data │ └── float.tif ├── test_mod.py └── test_cli.py ├── .travis.yml ├── .gitignore ├── README.rst ├── README.md ├── LICENSE └── setup.py /joydivision/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/data/float.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnomadb/rio-joydivision/HEAD/tests/data/float.tif -------------------------------------------------------------------------------- /tests/test_mod.py: -------------------------------------------------------------------------------- 1 | import metasay 2 | 3 | 4 | def test_msg(): 5 | metadata = {'count': 3, 'dtype': 'uint8', 'driver': 'GTiff'} 6 | assert "Count: 3" in metasay.moothedata(metadata, 'count') 7 | -------------------------------------------------------------------------------- /tests/test_cli.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | 3 | from click.testing import CliRunner 4 | 5 | from metasay.scripts.cli import metasay 6 | 7 | 8 | def test_cli_dtype(): 9 | filename = os.path.join(os.path.dirname(__file__), 'data/float.tif') 10 | runner = CliRunner() 11 | result = runner.invoke(metasay, [filename, '--item', 'dtype']) 12 | assert result.exit_code == 0 13 | assert "Dtype: float64" in result.output 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: python 3 | env: 4 | - RASTERIO_VERSION=0.26.0 5 | addons: 6 | apt: 7 | packages: 8 | - libgdal1h 9 | - gdal-bin 10 | python: 11 | - "2.7" 12 | - "3.4" 13 | cache: 14 | directories: 15 | - $HOME/.pip-cache/ 16 | - $HOME/wheelhouse 17 | before_install: 18 | - curl -L https://github.com/mapbox/rasterio/releases/download/$RASTERIO_VERSION/rasterio-travis-wheels-$TRAVIS_PYTHON_VERSION.tar.gz > /tmp/wheelhouse.tar.gz 19 | - tar -xzvf /tmp/wheelhouse.tar.gz -C $HOME 20 | install: 21 | - pip install --use-wheel --find-links=$HOME/wheelhouse -e .[test] --cache-dir $HOME/.pip-cache 22 | script: 23 | - py.test 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | 56 | # OS X 57 | .DS_Store 58 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | rio-joydivision 2 | =============== 3 | 4 | .. figure:: https://cloud.githubusercontent.com/assets/5084513/10010135/4cb38740-609b-11e5-92e4-348852a7d361.png 5 | :alt: image 6 | 7 | image 8 | 9 | Streams out moody post-punk geojson w/ y-offsets derived from raster 10 | data 11 | 12 | :: 13 | 14 | Usage: rio joydivision [OPTIONS] INPUTFILE 15 | 16 | LOVE 17 | 18 | WILL 19 | 20 | TEAR 21 | 22 | US 23 | 24 | APART 25 | 26 | Options: 27 | -r, --row-interval INTEGER Row interval to sample on [default = 1] 28 | -c, --col-interval INTEGER Column interval to sample on [default = 1] 29 | -f, --scaling-factor FLOAT Value to scale y-offset by [default = 1.0] 30 | -n, --nodata-set TEXT Value to set nodata to [default = None] 31 | --version Show the version and exit. 32 | --help Show this message and exit. 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rio-joydivision 2 | 3 | ![image](https://cloud.githubusercontent.com/assets/5084513/10010135/4cb38740-609b-11e5-92e4-348852a7d361.png) 4 | 5 | Streams out moody post-punk geojson w/ y-offsets derived from raster data. 6 | 7 | ## Install 8 | 9 | ``` 10 | pip install rio-joydivision 11 | ``` 12 | 13 | ## Usage 14 | 15 | ``` 16 | Usage: rio joydivision [OPTIONS] INPUTFILE 17 | 18 | LOVE 19 | 20 | WILL 21 | 22 | TEAR 23 | 24 | US 25 | 26 | APART 27 | 28 | Options: 29 | -r, --row-interval INTEGER Row interval to sample on [default = 1] 30 | -c, --col-interval INTEGER Column interval to sample on [default = 1] 31 | -f, --scaling-factor FLOAT Value to scale y-offset by [default = 1.0] 32 | -n, --nodata-set TEXT Value to set nodata to [default = None] 33 | -b, --bidx INTEGER Band to offset 34 | --version Show the version and exit. 35 | --help Show this message and exit. 36 | ``` 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Mapbox 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from codecs import open as codecs_open 2 | from setuptools import setup, find_packages 3 | 4 | # Get the long description from the relevant file 5 | with codecs_open('README.rst', encoding='utf-8') as f: 6 | long_description = f.read() 7 | 8 | with open('joydivision/__init__.py') as f: 9 | for line in f: 10 | if line.find("__version__") >= 0: 11 | version = line.split("=")[1].strip() 12 | version = version.strip('"') 13 | version = version.strip("'") 14 | break 15 | 16 | 17 | setup(name='rio-joydivision', 18 | version=version, 19 | description=u"Lines will tear us apart", 20 | long_description=long_description, 21 | classifiers=[], 22 | keywords='', 23 | author=u"Damon Burgett", 24 | author_email='damon@mapbox.com', 25 | url='https://github.com/dnomadb/rio-joydivision', 26 | license='BSD', 27 | packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), 28 | include_package_data=True, 29 | zip_safe=False, 30 | install_requires=[ 31 | 'click', 32 | 'rasterio', 33 | 'shapely' 34 | ], 35 | extras_require={ 36 | 'test': ['pytest'], 37 | }, 38 | entry_points=""" 39 | [rasterio.rio_commands] 40 | joydivision=joydivision.scripts.cli:joydivision 41 | """ ) 42 | -------------------------------------------------------------------------------- /joydivision/scripts/cli.py: -------------------------------------------------------------------------------- 1 | # Moothedata command. 2 | 3 | import sys 4 | 5 | import click 6 | import rasterio 7 | 8 | import joydivision as jd 9 | 10 | from joydivision import __version__ as joy_version 11 | 12 | 13 | @click.command(short_help="") 14 | @click.argument('inputfile', type=click.Path(exists=True), required=True) 15 | @click.option('--row-interval', '-r', default=1, type=int, help="Row interval to sample on [default = 1]") 16 | @click.option('--col-interval', '-c', default=1, type=int, help="Column interval to sample on [default = 1]") 17 | @click.option('--scaling-factor', '-f', default=1.0, type=float, help="Value to scale y-offset by [default = 1.0]") 18 | @click.option('--nodata-set', '-n', default=None, help="Value to set nodata to [default = None]") 19 | @click.option('--bidx', default=1, type=int, help="Band to joyifiy [DEFAULT=1]") 20 | @click.option('--gtype', '-t', default='LineString', type=click.Choice(['Polygon', 'LineString']), help="Output geom type [default = LineString]") 21 | @click.version_option(version=joy_version, message='%(version)s') 22 | @click.pass_context 23 | def joydivision(ctx, inputfile, row_interval, col_interval, scaling_factor, nodata_set, bidx, gtype): 24 | ''' 25 | LOVE\n 26 | WILL\n 27 | TEAR\n 28 | US\n 29 | APART''' 30 | jd.joydivision(inputfile, row_interval, col_interval, scaling_factor, nodata_set, bidx, gtype) 31 | -------------------------------------------------------------------------------- /joydivision/__init__.py: -------------------------------------------------------------------------------- 1 | import rasterio as rio 2 | import numpy as np 3 | import click 4 | import json 5 | 6 | from shapely.geometry import Polygon, LineString 7 | 8 | __version__ = '1.1.1' 9 | 10 | def offset_rad_poly(lngs, lats, valRow, bounds, scaling_factor): 11 | return np.concatenate([ 12 | np.dstack([lngs, lats + valRow * scaling_factor])[0], 13 | [[bounds.right, lats[-1]]], 14 | [[bounds.right, bounds.bottom]], 15 | [[bounds.left, bounds.bottom]], 16 | [[bounds.left, lats[0]]] 17 | ]) 18 | 19 | def offset_rad_line(lngs, lats, valRow, bounds, scaling_factor): 20 | return np.concatenate([ 21 | np.dstack([lngs, lats + valRow * scaling_factor])[0], 22 | [[bounds.right, lats[-1]]] 23 | ]) 24 | 25 | def make_point_grid(rows, cols, bounds): 26 | return np.array( 27 | [ 28 | np.arange(bounds.left, bounds.right, ((bounds.right - bounds.left) / float(cols))) for i in range(rows) 29 | ]), np.rot90(np.array([ 30 | np.arange(bounds.bottom, bounds.top, ((bounds.top - bounds.bottom) / float(rows))) for i in range(cols) 31 | ]) 32 | ) 33 | 34 | 35 | def joydivision(inputfile, row_interval, col_interval, scaling_factor, nodata_set, bidx, gtype): 36 | with rio.open(inputfile) as src: 37 | bounds = src.bounds 38 | rasVals = np.zeros(( 39 | int(src.height / float(row_interval)), 40 | int(src.width / float(col_interval)) 41 | ), dtype=src.meta['dtype']) 42 | 43 | src.read(bidx, out=rasVals) 44 | cellsize = src.affine.a 45 | 46 | if nodata_set: 47 | rasVals[np.where(rasVals == src.nodata)] = nodata_set 48 | 49 | rows, cols = rasVals.shape 50 | 51 | lngs, lats, = make_point_grid(rows, cols, bounds) 52 | 53 | 54 | for r in xrange(rows): 55 | 56 | xy = offset_rad_line(lngs[r], lats[r], rasVals[r], bounds, scaling_factor) 57 | 58 | if gtype == 'LineString': 59 | polygon = LineString(xy.tolist()) 60 | polygon = polygon.simplify(cellsize) 61 | 62 | click.echo(json.dumps({ 63 | "type": "Feature", 64 | "properties": { 65 | 'row': r 66 | }, 67 | "geometry": { 68 | "type": "LineString", 69 | "coordinates": [xy for xy in polygon.coords] 70 | } 71 | })) 72 | 73 | else: 74 | polygon = Polygon(xy.tolist()) 75 | polygon = polygon.simplify(cellsize) 76 | 77 | click.echo(json.dumps({ 78 | "type": "Feature", 79 | "properties": { 80 | 'row': r 81 | }, 82 | "geometry": { 83 | "type": "Polygon", 84 | "coordinates": [[xy for xy in polygon.exterior.coords]] 85 | } 86 | })) 87 | 88 | if __name__ == '__main__': 89 | joydivision() --------------------------------------------------------------------------------