3

I often end up writing basic geometries in unit tests, looking much like the following:

a = "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))";
b = "POLYGON ((0 0, 9 0, 9 9, 0 9, 0 0))";

If I'm feeling ambitious, I might add a comment like this:

// ----------------------
// |      A             |
// |-----------------|  |
// |                 |  |
// |                 |  |
// |        B        |  |
// |                 |  |
// |                 |  |
// ----------------------

Clearly the technique has some limitations. But it can be useful, which lead me to wonder if there's a magic tool out there that would take WKT (or something easily producible, like SVG) and create an ASCII representation like the example above?

Google led me to Geometry Commands, through I was disappointed to see that their asciiart command produces the following:

 ____    ___   _     __   __  ____   ___   _   _     __  __  ___      ___        _   ___      ___        _   ___     _   ___         ___     _   ___         ___      ___  __  __  
|  _ \  / _ \ | |    \ \ / / / ___| / _ \ | \ | |   / / / / / _ \    / _ \      / | / _ \    / _ \      / | / _ \   / | / _ \       / _ \   / | / _ \       / _ \    / _ \ \ \ \ \ 
| |_) || | | || |     \ V / | |  _ | | | ||  \| |  | | | | | | | |  | | | | _   | || | | |  | | | | _   | || | | |  | || | | | _   | | | |  | || | | | _   | | | |  | | | | | | | |
|  __/ | |_| || |___   | |  | |_| || |_| || |\  |  | | | | | |_| |  | |_| |( )  | || |_| |  | |_| |( )  | || |_| |  | || |_| |( )  | |_| |  | || |_| |( )  | |_| |  | |_| | | | | |
|_|     \___/ |_____|  |_|   \____| \___/ |_| \_|   \_\ \_\ \___/    \___/ |/   |_| \___/    \___/ |/   |_| \___/   |_| \___/ |/    \___/   |_| \___/ |/    \___/    \___/ /_/ /_/ 

Nice, but not quite what I was going for. Anyone aware of another tool out there?

12
  • 1
    I'm thinking this is borderline if not completely off-topic for GIS SE
    – Midavalo
    Sep 7, 2016 at 18:39
  • 1
    Wondering if there could be a route by using SVG as an interim format.
    – user30184
    Sep 7, 2016 at 19:27
  • 1
    Can you explain why you think that your question is relevant to GIS?
    – PolyGeo
    Sep 7, 2016 at 20:17
  • 1
    More concise titles work better for sharing questions via Twitter etc. There are some Meta posts here and at Meta SE that recommend "How to" not be used at the beginning of question titles on SE sites.
    – PolyGeo
    Sep 7, 2016 at 20:31
  • 1
    Certainly WKT is a GIS format. I think you are saying that being able to convert from it into ASCII art would assist you to better document your GIS code. To me that would make it on-topic.
    – PolyGeo
    Sep 7, 2016 at 22:11

1 Answer 1

4

Well, this isn't perfect, but it's better than anything I've seen so far. Here's a command-line process that uses three commands:

  1. The wellknown command reads WKT from stdin and write GeoJSON.
  2. The geotype command reads GeoJSON from stdin and outputs a map, using color ANSI escape sequences.
  3. Good old-fashioned sed strips out these sequences.

The three commands can be piped together like this:

echo 'POLYGON ((0 0, 0 1, 1 1, 0 0))' | \
  wellknown | \
  geotype -z 12 | \
  sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"

Which outputs the following:

  ::::::::::::::::::::::::  
  ::::::::::::::::::::::    
  ::::::::::::::::::::      
  ::::::::::::::::::        
  ::::::::::::::::          
  ::::::::::::::            
  ::::::::::::::            
  ::::::::::::              
  ::::::::::                
  ::::::::                  
  ::::::                    
  ::::                      
  ::                        

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.