Package: gj2ascii
_ ___                   _ _
   ____ _  (_)__ \ ____ ___________(_|_)
  / __ `/ / /__/ // __ `/ ___/ ___/ / /
 / /_/ / / // __// /_/ (__  ) /__/ / /
 \__, /_/ //____/\__,_/____/\___/_/_/
/____/___/Render spatial vector data as ASCII or emoji with Python on the commandline.Why?Atweetmade it seem like an interesting exercise but
thegj2asciicommandline utility has been very useful for previewing multiple files and the API has proven to be
useful for debugging complex geoprocessing operations.Default BehaviorThe overall goal of this utility is to provide easy access to ASCII representations
of vector geometries and overlapping layers.When rendering a single layer an ASCII character is used.When rendering multiple layers colors are used with a randomly assigned character underneath and a transparent fill.There are only7colors (black is not used for auto-assignment) so if more than 7 layers
are given the--charflag must be used for each of them to manually assign a character,
emoji, or color.Emoji ExampleThe emoji screenshot was generated by downloading theGeoTIFFversion of theMODIS Landcover dataset, resampling to25%of its original, size converted to a vector withgdal_polygonize.py,
andsplitinto oneESRI Shapefileper class withQGIS, before executing the following
command:$gj2ascii\--bbox-1309-61.577\--width80\0.geojson-c' '\1.geojson-c:christmas_tree:\2.geojson-c:evergreen_tree:\3.geojson-c:maple_leaf:\4.geojson-c:maple_leaf:\5.geojson-c:deciduous_tree:\6.geojson-c:herb:\7.geojson-c:herb:\8.geojson-c:herb:\9.geojson-c:herb:\10.geojson-c:ear_of_rice:\11.geojson-c:turtle:\12.geojson-c:tractor:\13.geojson-c:house_building:\14.geojson-c:leaf_fluttering_in_wind:\15.geojson-c:snowflake:\16.geojson-c:black_medium_square:The same data can be rendered with ASCII characters instead:$gj2ascii\--bbox-1309-61.577\--width80\0.shp-c' '\1.shp-c\#\2.shp-c\^\3.shp-c+\4.shp-c\&\5.shp-c\$\6.shp-c\%\7.shp-c\:\8.shp-cP\9.shp-c-\10.shp-c\"\11.shp-c0\12.shp-c=\13.shp-cN\14.shp-c\@\15.shp-c\*\16.shp-cOOther ExamplesSee theexamples directoryfor more information and
more complex examples but the following are a good place to get started.  Some of the examples include output that
would be colored if run on the commandline or in Python but RST cannot render the ANSI codes.Render two layers, one read from stin and one read directly from a file, across 20 pixels while explicitly specifying
a character and color for each layer and background fill, and zooming in on an area of interest.$catsample-data/polygons.geojson|gj2ascii-\sample-data/lines.geojson\--bboxsample-data/small-aoi-polygon-line.geojson\--width20\--char^=red\--char-=blue\--fill.=green. . . . . . - . . . . . . . . . ^ ^ ^ ^
. . . . . - . . . . . . . . . . . ^ ^ ^
. . . . - . . . . . . . . . . . . . - -
. . . . - . . . . . . . . - - - - - . ^
^ ^ . - . . . . . . . . . . . . . . . .
^ ^ - . . . . . . . . . . . . . . . . .
^ - ^ . . . . . . . . . . . . . . . . .
^ - . . . . . . . . . . . . . . . . . .
- ^ . . . . . . - . . . . . ^ . . . . .
. - . . . . . . - - . . . ^ ^ . . . . .
. . - . . . . . - . - . ^ ^ ^ . . . . .
. . . - . . . . - . . - ^ ^ ^ . . . . .
. . . . - . . - . . ^ ^ - ^ ^ . . . . .
. . . . . - . - . ^ ^ ^ ^ - ^ . . . . .
. . . . . . - - ^ ^ ^ ^ ^ ^ - . . . . .Render individual features across 10 pixels and display the attributes for two
fields,COUNTYFPandNAME.$gj2asciisample-data/WV.geojson\--iterate\--propertiesCOUNTYFP,NAME\--width10+----------+---------+
| COUNTYFP |     001 |
| NAME     | Barbour |
+----------+---------+

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

Press enter for the next geometry or ^C/^D or 'q' to quit...Recreate the first example with the Python APIThere are two ways to recreate the first example with the Python API.  If the user does not care about which characters
are assigned to which color, use this one:importfionaasfioimportgj2asciiwithfio.open('sample-data/polygons.geojson')aspoly,\fio.open('sample-data/lines.geojson')aslines,\fio.open('sample-data/small-aoi-polygon-line.geojson')asbbox:layermap=[(poly,'red'),(lines,'blue')]print(gj2ascii.style_multiple(layermap,20,fill='green',bbox=bbox.bounds))000000100000000022220000010000000000022200001000000000000011000010000000011111022201000000000000000022100000000000000000212000000000000000002100000000000000000012000000100000200000010000001100022000000010000010102220000000010000100122200000000010010022122000000000010102222120000000000011222222100000If the user cares about which character is assigned to which layer, use this one:importfionaasfioimportgj2asciiwithfio.open('sample-data/polygons.geojson')aspoly,\fio.open('sample-data/lines.geojson')aslines,\fio.open('sample-data/small-aoi-polygon-line.geojson')asbbox:# Render each layer individually with the same bbox and width# The fill will be assigned in the next step but must be a single space hererendered_layers=[gj2ascii.render(poly,20,char='^',fill=' ',bbox=bbox.bounds),gj2ascii.render(lines,20,char='-',fill=' ',bbox=bbox.bounds)]# Overlay the rendered layers into one stackstacked=gj2ascii.stack(rendered_layers,fill='.')# Apply the colors and printcolormap={'^':'red','-':'blue','.':'green'}print(gj2ascii.style(stacked,colormap))......-.........^^^^.....-...........^^^....-.............--....-........-----.^^^.-................^^-.................^-^.................^-..................-^......-.....^......-......--...^^.......-.....-.-.^^^........-....-..-^^^.........-..-..^^-^^..........-.-.^^^^-^...........--^^^^^^-.....Paginating through features:importfionaasfioimportgj2asciiwithfio.open('sample-data/WV.geojson')assrc:forfeatureingj2ascii.paginate(src,10,properties=['COUNTYFP','NAME']):print(feature)+----------+---------+|COUNTYFP|001||NAME|Barbour|+----------+---------+++++++++++++++++++++++++++++++++++++++++++++++++++++++InstallationVia pip:$pipinstallgj2ascii--upgradeFrom master branch:$gitclonehttps://github.com/geowurster/gj2ascii.git$cdgj2ascii$pythonsetup.pyinstallTo enable emoji:$pipinstallgj2ascii[emoji]DependenciesThe 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:RasterioFionaShapelySome Linux distributions require an additional step before installing rasterio:apt-getinstallpython-numpy-devlibgdal1hlibgdal-dev.Developing$gitclonehttps://github.com/geowurster/gj2ascii.git$cdgj2ascii$virtualenvvenv$sourcevenv/bin/activate$pipinstall-e.[all]$py.testgj2ascii--covgj2ascii--cov-reportterm-missingLicenseSeeLICENSE.txt.