Skip to main content

Print countries in ASCII Art based on Natural Earth shape files.

Project description

Natural Earth

asciimap

Print countries in ASCII Art based on shape files from Natural Earth project

Code Style: Black License Python Version GitHub tag (latest SemVer) Travis (.com) branch

        *-----*                                 $-----$                                 '-----'                    
       *     /                                 $     /                                 '     /                     
       *    *                                  $    $                                  '    '                      
      *      *-----*                          $      $-----$                          '      '-----'               
      |           |                           |           |                           |           |                
      |           *                           |           $                           |           '                
      *          /                            $          /                            '          /                 
       *        /                              $        /                              '        /                  
       |       *                               |       $                               |       '                   
       |-*      *--*                           |-$      $--$                           |-'      '--'               
       *  *         *                          $  $         $                          '  '         '              
         *          *                            $          $                            '          '              
 *--*     *--*       \                   $--$     $--$       \                   '--'     '--'       \             
 |   **       \       \                  |   $$       \       \                  |   ''       \       \            
 *\  |         \       *-*               $\  |         \       $-$               '\  |         \       '-'         
   *-*          *        *                 $-$          $        $                 '-'          '        '         
                United Kingdom                          United Kingdom                          United Kingdom     
           *--* *         *                        $--$ $         $                        '--' '         '        
          *    *           \                      $    $           \                      '    '           \       
          *                 **                    $                 $$                    '                 ''     
           \                  \*                   \                  \$                   \                  \'   
            *                  *                    $                  $                    '                  '   
        *--/                  *                 $--/                  $                 '--/                  '    
         *----*               |                  $----$               |                  '----'               |    
               *              |                        $              |                        '              |    
           *--*              /*                    $--$              /$                    '--'              /'    
          /     ** *--------*                     /     $$ $--------$                     /     '' '--------'      
         /-----*  *                              /-----$  $                              /-----'  '                
       *-*                                     $-$                                     '-'                         

You can print any country with asciimap for which a Geometry exists (currently 177 countries). In general printing is pretty fast though big countries like Russia, Canada etc. need some extra computation time. To circumvent loading times store the results in a database or similar. Disk space isn't much for normal 40x80 sized ascii maps.

Dependencies

You need the python bindings for GDAL and GDAL itself installed. I experienced problems installing the python bindings into a virtualenv, so I recommend installing the system packages.

Arch

pacman -Sy gdal python-gdal

Debian/Ubuntu

apt-get update
apt-get install gdal-bin libgdal-dev python3-gdal

Installation

PyPi

Installation with pip is straightforward:

sudo pip install asciimap

Git

Installation with git from master branch:

git clone git@github.com:MaelStor/asciimap.git
cd asciimap
git checkout master
In userspace

Install in user space with:

pip install --user .
System

Install system wide with:

sudo pip install .

Usage

usage: asciimap [-h] [--fill FILL] [--height HEIGHT] [--width WIDTH]
                [--empty EMPTY] [--blur BLUR]
                [--method {full,f,dynamic,d,height,h,width,w}]
                country

Print countres in ASCII Art

positional arguments:
  country               Select country by ISO 3166-1 alpha-2 codes

optional arguments:
  -h, --help            show this help message and exit
  --fill FILL, -f FILL  Single character
  --height HEIGHT, -i HEIGHT
                        Height of the map
  --width WIDTH, -w WIDTH
                        Width of the map
  --empty EMPTY, -e EMPTY
                        The character to use for empty space
  --blur BLUR, -b BLUR  Add blur to radius and inflate the map
  --method {full,f,dynamic,d,height,h,width,w}, -m {full,f,dynamic,d,height,h,width,w}
                        Change rendering method

List all countries and ISO 3166-1 alpha-2 codes with 'list'

Examples

$ asciimap --blur 0.1 it
              *  *---*                                                          
              *-*     *--*                                                      
         *---*            **                                                    
      *  /                *                                                     
 *---* **                  *                                                    
 *                    *----*                                                    
  *                  *                                                          
 *                   |                                                          
 |                   |                                                          
 |                   *                                                          
 *\    *--*           \                                                         
   \ **    *-*         \                                                        
   **         *         **                                                      
              |           \                                                     
              *            *                                                    
               \           *                                                    
                \           \                                                   
                 \  Italy    **                                                 
                  \            \                                                
                   **           *--*                                            
                     **            \                                            
                       *--*         **                                          
        *-*                \          **                                        
      */   \                **          **                                      
      *     *                 \        /  **                                    
       *    *                  **     / *-* *                                   
       |   *                     \   *     **                                   
       |   |                      *  *                                          
       |   |                      *   \*                                        
       * *-*                       *   |                                        
        *                          |  /*                                        
                                   * /                                          
                                  / /                                           
                      *----------/ /*                                           
                      |         | *                                             
                      *\        |                                               
                        *-*     |                                               
                           *-*  |                                               
                              *-*                                               

$ asciimap --blur 0.1 no
                       *---------------*                                        
          *-----------* \  |  /------*                                          
           *\            *---*                                                  
             **          /     *                                                
               \       **    *----*                                             
                *-*   /                                                         
                   *-*                                                          









                                   *------*                                     
                                 **     /  *--*                                 
                          *-----*     ** \   |                                  
                   Norway/ /--\     **    *--*                                  
                     * *--*    *---*                                            
                   *--*                                                         
                 ** /                                                           
                /  /                                                            
               /  /                                                             
             **  /                                                              
            /   /                                                               
           /   /                                                                
         **   /*                                                                
       **    /                                                                  
    *-*     *                                                                   
  **        |                                                                   
 *          *                                                                   
 |           *                                                                  
 |           |                                                                  
 |           *                                                                  
 |       ** /                                                                   
 *      /  *                                                                    
  *----*                                                                        

Advanced usage

Some advanced usage with command-line tools. The picture in the title was produced with

$ asciimap gb --height 30 --width 35 | paste - <(asciimap gb --height 30 --width 35 --fill "$") | paste - <(asciimap gb --height 30 --width 35 --fill "'")

another example with 'paste' and usage of 'blur':

$ asciimap -b 0 jp -i 30 -w 30 | paste - <(asciimap -b 2.0 jp -i 30 -w 30)
                                                    *--*      
                       **                           /   \     
                       | \                         /     *--* 
                       *  *--*                    /          *
                     **     /*                   *           |
                    *  \   /                     *           |
                    | * *-*                     *            |
                    * |                         |            |
                     /|                         |          *-*
                    * \                         |         /   
                    |  *                        |        /    
                    |  |                        *       *     
                    *  *                     *-*        |     
                   /  /                     /           *     
                  *  *                     /   Japan   *      
               Japan |                 *--*            *      
             **      *               **               *       
             /      *               /                 |       
            /        *            **                  |       
      *----/       **            *                    *       
     /    /   *---*              |                  **        
   *-*   / \ /                   |              *--*          
  /*  \ / /-*                    |            **              
 *  *--* *                       *         *-*                
 *  |                             *      **                   
  \ *                             *     /                     
  **                               *---*                      

$ asciimap au --blur 0.1 --empty '.' --method full
.....................................*-*.................**.....................
..................................../...*-----*........../.\....................
..................................**..........*.........*...*...................
...........................*.....*.........../..........|...*...................
........................*-*.**...*..........*...........|....*-*................
......................**......*-*............**.........|......\................
...................../.........................**.......*.......*...............
..................*-*............................*-*.../........*...............
................../.................................*-*..........*..............
................./...............................................*..............
...............**.................................................*-*...........
.........*----*......................................................**.........
.....*--*..............................................................\........
..*-*...................................................................**......
.*........................................................................\.....
.|.........................................................................\....
.*..........................................................................**..
..*...........................................................................\.
.*........................................Australia............................*
..*............................................................................|
..*............................................................................|
...\...........................................................................|
....*..........................................................................|
....*..........................................................................*
.....*........................*--------*....................................../.
.....|.................*-----*..........**.................................../*.
.....*................/...................\.....*.........................../...
....*.......*--------*.....................\..**.*........................./....
.....*-----*................................**..**......................../.....
..................................................*-*....................*......
.....................................................*...................*......
.....................................................*................*-*.......
......................................................*----*.*--*..*-*..........
............................................................*....**.............
................................................................................
................................................................................
...............................................................*-----*..........
................................................................|....*..........
................................................................*---*...........
................................................................................

Sometimes a country has more than one land surface (or more precise: Polygons) defined which scrambles the surface of interest when printing all surfaces:

$ asciimap --surface all --method full ru --fill "'"
                                                             ''                 
                                                             '\                 
                                                               '                
                                                               '                
                                                      ''      / \'              
                                                     '      '/   '     '-'      
                                                            /   '               
                                                    '     '/     '' '           
                                                    |   ' /        \|  '-'      
                                                    '  ' '          \ /  \      
                                                       '             '    ''    
                                               '      / '                   '--'
                                               |\ '  / '                       |
 '                                             |-\ ''                          |
 |'                                            |  /                            |
 '                                             | '                             |
                                               | '                             |
                                               |/                              |
                                               |                           ''  '
                                               |             Russia       '  '/ 
                                               |                        ' | '/  
                                               |                       ' '' |   
                                               |                       '    |   
                                               |                      '    '|   
                                               |                      |    |'   
                                               |       '-'            '    |    
                                               '      /   '        '   '   |    
                                                '    /    |       ' \  |   |    
                                                |   /|    '   '   |  ' |   '    
                                                '  / '     \ / \  |  | |        
                                                 \/        ''  '--'  | '        
                                                 ||                  '  '       
                                                 ||                   '/        
                                                 ||                   |         
                                                 /|                   |         
                                                ' |                   |         
                                                 \|                   '         
                                                  '                             


To overcome the bias you can just render the big land surface for example with:

$ asciimap --surface 1 --method height ru --fill "'" 
                                           '-'                                  
                                   '-----'                              '------'
                                '---'                             '----'       |
                              '' /                               /             |
                             / ''                          '----'              |
                            ' /               '--'     '-' /                   |
                            '--'            '/  \  '' /   '                    |
                                            |    '  ''                         |
    '-'                             '--'    '\   ' /                           |
  ''   '---'                ''    '' /  '--'  '   / \                          |
   |        \-'    ''   '--'  '--'  '       ''   /'  '                         |
   '     '-----\   /\ ''                        '  ''                          |
    '   '      |--'  '                           ''                            |
   '    '  '   /                                                               |
    \    '' '-'                                                                |
     '                                                                         |
    /                                                                          |
   /                                                                     Russia|
  /                                                                            |
 '                                                                             |
 |                                                                             |
 |                                                                             |
 '\                                                                            |
   \                                        '--'                               |
    \                                 '----'    '-'  ''                        |
     \                               '             ''  \                       |
     |-'                             '                  \                      |
     '  \                '---'      /                    \                    /'
         \ '            /     '------'                    '---'       '--'   /  
          ' ''        ''                                       '-' '-'    '--'  
              '      '                                            '             
              '      '                                                          
             /        \                                                         
            '          '                                                        
       ''   |         /                                                         
       ''  '-\       '                                                          
              '--'   '                                                          
                  '-' \                                                         
                     '-'                                                        

what cuts off the right half of Russia. To print the whole surface:

$ asciimap --surface 1 --method width --height 20 ru --fill "'"
                                         ''                                      
                '-'              '-----'  '--'            '--'                  
               /            '---'             ''   '        /                   
             ''       '' '-'                    '-' '' '   / '--'               
                     / \ /                            ' '-'      '---'     '--' 
  '---'  '' '-------'   '                                             '---'    '
  |/    /  '                                                                   |
  | \ ''                                                                      /'
  '  '                                                             '--'   ' ''  
 '                                  Russia                  '-----'    '-' '    
 |                                                        ''         ''         
 '                   ''                                  '          '  '        
  \               '-'  '--'                      '-'     '          |-'         
   ''       '----'         '-'    '   ''        /   \     \-'       '           
     ''    /     '            '--' '-'  '-------'    ''    |                    
       '  '                                            \   '                    
      '    '                                            \ /                     
    ' '-' /                                            '-'                      
         ''                                                                     

To find the right surface you have to try around a bit. I'm working on a better solution.

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

asciimap-0.1.0b0.tar.gz (418.0 kB view hashes)

Uploaded Source

Built Distribution

asciimap-0.1.0b0-py3-none-any.whl (416.7 kB view hashes)

Uploaded Python 3

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