Skip to main content

Render GeoJSON as ASCII on the commandline.

Project description

            _ ___                   _ _
   ____ _  (_)__ \ ____ ___________(_|_)
  / __ `/ / /__/ // __ `/ ___/ ___/ / /
 / /_/ / / // __// /_/ (__  ) /__/ / /
 \__, /_/ //____/\__,_/____/\___/_/_/
/____/___/
https://travis-ci.org/geowurster/gj2ascii.svg?branch=master https://coveralls.io/repos/geowurster/gj2ascii/badge.svg?branch=master

Render GeoJSON on the commandline. Inspired by @wboykinm, @dnomadb, and a tweet.

Examples

Get help:

$ gj2ascii --help

Render the entire layer in a block 20 pixels wide:

$ gj2ascii sample-data/polygons.geojson --width 20

  +                       +
  + + +
      +
                          +
                  +
                  + +
                  + + + +
                    + + + +
                      + + +         +
+ + +                   + +       + + +
+ + + +                         + + + +
    +             +               + +
                + +                 +
              + + +                 +
            + + + +
            + + + +
                + +

Read from stdin and render all pixels any geometry touches across 15 pixels:

$ cat sample-data/polygons.geojson | gj2ascii - --width 15 --all-touched

+ + + +           + +
+ + + +           + +
    + +           + +
            + + +
            + + + +
              + + + +     +
+ +           + + + +   + + +
+ + +           + + +   + + +
+ + +       + +         + + +
          + + +         + + +
        + + + +           + +
        + + + +
          + + +

Render individual features across 10 pixels and display the attributes for two fields, COUNTYFP and NAME.

$ gj2ascii sample-data/WV.geojson --iterate --properties COUNTYFP,NAME --width 10

+----------+---------+
| COUNTYFP |     001 |
| NAME     | Barbour |
+----------+---------+

            + + +
  +   + + + + + + +
  + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + +
    + + + + + + +
        + + + +
        + + + +

Press enter for the next geometry or ^C/^D or 'q' to quit...

+----------+---------+
| COUNTYFP |     013 |
| NAME     | Calhoun |
+----------+---------+

        + +
      + + + + +
    + + + + + + +
+ + + + + + + + +
+ + + + + + + + +
  + + + + + + + +
  + + + + + + + +
    + + + + + + +
    + + + + + +
      + + + + +
        + + + + + +
        + + + + + +
        + + + + +
        + + + +

Press enter for the next geometry or ^C/^D or 'q' to quit...

Installation

Via pip:

$ pip install gj2ascii

From master branch:

$ git clone https://github.com/geowurster/gj2ascii.git
$ cd gj2ascii
$ python setup.py install

Dependencies

The dependencies are pretty heavy for a utility like this and may require some extra work to get everything installed. All dependencies should install on their own but there are a few potentially problematic packages. Manually installing the following might help:

Some Linux distributions require an additional step before installing rasterio: apt-get install python-numpy-dev

API

Render an entire layer:

with open('sample-data/lines.geojson') as f:
    features = json.load(f)
    ascii = gj2ascii.render(features['features'], 20)
print(ascii)
+ + + + + + + + +           +
  +                         +
    +                         +
      +                       +
        +                       +
          +                     +
        +                         +
        +                         +
      +         + + + + + + +     +
    +                               +
  +                                 +
  +                                   +
+         +                           +
  +       + +
    +     +   +
      + +       +

Render a single feature:

import json
import gj2ascii
with open('sample-data/lines.geojson') as f:
    features = json.load(f)
    ascii = gj2ascii.render([features['features'][0]], 15)
print(ascii)
              + + + + + + +
+ + + + + + +
+
  + +
      +
        +
          + +
              +
                +
              +
            +
            +
          +
        +
      +
    +
    +
  +
+               +
  +             + +
    +           +   +
      +         +   +
        +     +       +
          +   +         +
            + +           +
              +           +

Get the properties as a formatted table:

import json
import gj2json
with open('sample-data/WV.geojson') as f:
    features = json.load(f)
    table = gj2ascii.dict_table(features['features'][0]['properties'])
print(table)
+----------+----------------+
| INTPTLAT |    +39.1397248 |
| NAME     |        Barbour |
| ALAND    |      883338808 |
| CLASSFP  |             H1 |
| FUNCSTAT |              A |
| INTPTLON |   -079.9969466 |
| LSAD     |             06 |
| METDIVFP |           None |
| GEOID    |          54001 |
| AWATER   |        4639183 |
| COUNTYFP |            001 |
| CSAFP    |           None |
| CBSAFP   |           None |
| MTFCC    |          G4020 |
| NAMELSAD | Barbour County |
| STATEFP  |             54 |
| COUNTYNS |       01696996 |
+----------+----------------+

Developing

$ git clone https://github.com/geowurster/gj2ascii.git
$ cd gj2ascii
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements-dev.txt
$ pip install -e .
$ nosetests --with-coverage

License

See LICENSE.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gj2ascii-0.3.0.tar.gz (10.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page