在命令行中将geojson呈现为ascii。
gj2ascii的Python项目详细描述
_ ___ _ _
____ _ (_)__ \ ____ ___________(_|_)
/ __ `/ / /__/ // __ `/ ___/ ___/ / /
/ /_/ / / // __// /_/ (__ ) /__/ / /
\__, /_/ //____/\__,_/____/\___/_/_/
/____/___/
在命令行上使用python将空间矢量数据呈现为ascii或emoji。
为什么?
一个tweet使它看起来像一个有趣的练习,但是 gj2ascii命令行实用程序对于预览多个文件非常有用,而且api已经被证明是 用于调试复杂的地理处理操作。
默认行为
此实用程序的总体目标是提供对ascii表示的简单访问 矢量几何和重叠层。
- 渲染单层时,使用ascii字符。
- 渲染多个层时,颜色与下面随机分配的字符和透明填充一起使用。
只有7种颜色(黑色不用于自动分配),因此如果超过7层 如果给定--char标记,则每个标记都必须用于手动分配字符, 表情符号或颜色。
表情符号示例
emoji截图是通过下载 MODIS Landcover dataset,重新采样到25% 它的原始大小转换成一个向量,gdal_polygonize.py, 和split 在执行以下操作之前,在每个类中放入一个ESRI Shapefile和QGIS 命令:
$ gj2ascii \ --bbox -130 9 -61.5 77\ --width 80\ 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:
同样的数据可以用ascii字符代替:
$ gj2ascii \ --bbox -130 9 -61.5 77\ --width 80\ 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 -c P \ 9.shp -c - \ 10.shp -c \"\ 11.shp -c 0\ 12.shp -c =\ 13.shp -c N \ 14.shp -c \@\ 15.shp -c \*\ 16.shp -c O
其他示例
有关详细信息,请参见examples directory。 更复杂的例子,但下面是一个很好的开始。一些例子包括 如果在命令行或python中运行,则将被着色,但rst无法呈现ansi代码。
在显式指定 每个图层和背景填充的字符和颜色,并放大感兴趣的区域。
$ cat sample-data/polygons.geojson | gj2ascii - \ sample-data/lines.geojson \ --bbox sample-data/small-aoi-polygon-line.geojson \ --width 20\ --char ^=red \ --char -=blue \ --fill .=green . . . . . . - . . . . . . . . . ^ ^ ^ ^ . . . . . - . . . . . . . . . . . ^ ^ ^ . . . . - . . . . . . . . . . . . . - - . . . . - . . . . . . . . - - - - - . ^ ^ ^ . - . . . . . . . . . . . . . . . . ^ ^ - . . . . . . . . . . . . . . . . . ^ - ^ . . . . . . . . . . . . . . . . . ^ - . . . . . . . . . . . . . . . . . . - ^ . . . . . . - . . . . . ^ . . . . . . - . . . . . . - - . . . ^ ^ . . . . . . . - . . . . . - . - . ^ ^ ^ . . . . . . . . - . . . . - . . - ^ ^ ^ . . . . . . . . . - . . - . . ^ ^ - ^ ^ . . . . . . . . . . - . - . ^ ^ ^ ^ - ^ . . . . . . . . . . . - - ^ ^ ^ ^ ^ ^ - . . . . .
在10个像素上渲染各个特征,并显示两个的属性 字段,COUNTYFP和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...
使用python api重新创建第一个示例
有两种方法可以使用python api重新创建第一个示例。如果用户不关心哪个字符 指定给哪个颜色,请使用此颜色:
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))000000100000000022220000010000000000022200001000000000000011000010000000011111022201000000000000000022100000000000000000212000000000000000002100000000000000000012000000100000200000010000001100022000000010000010102220000000010000100122200000000010010022122000000000010102222120000000000011222222100000
如果用户关心分配给哪个层的字符,请使用此字符:
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))......-.........^^^^.....-...........^^^....-.............--....-........-----.^^^.-................^^-.................^-^.................^-..................-^......-.....^......-......--...^^.......-.....-.-.^^^........-....-..-^^^.........-..-..^^-^^..........-.-.^^^^-^...........--^^^^^^-.....
通过功能分页:
importfionaasfioimportgj2asciiwithfio.open('sample-data/WV.geojson')assrc:forfeatureingj2ascii.paginate(src,10,properties=['COUNTYFP','NAME']):print(feature)+----------+---------+|COUNTYFP|001||NAME|Barbour|+----------+---------+++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装
通过PIP:
$ pip install gj2ascii --upgrade
来自主分支:
$ git clone https://github.com/geowurster/gj2ascii.git $cd gj2ascii $ python setup.py install
要启用表情符号:
$ pip install gj2ascii[emoji]
开发
$ git clone https://github.com/geowurster/gj2ascii.git $cd gj2ascii $ virtualenv venv $source venv/bin/activate $ pip install -e .[all]$ py.test gj2ascii --cov gj2ascii --cov-report term-missing
许可证
见LICENSE.txt。