在命令行中将geojson呈现为ascii。

gj2ascii的Python项目详细描述


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

在命令行上使用python将空间矢量数据呈现为ascii或emoji。

https://raw.githubusercontent.com/geowurster/gj2ascii/master/images/emoji-land-cover-80w.png

为什么?

一个tweet使它看起来像一个有趣的练习,但是 gj2ascii命令行实用程序对于预览多个文件非常有用,而且api已经被证明是 用于调试复杂的地理处理操作。

默认行为

此实用程序的总体目标是提供对ascii表示的简单访问 矢量几何和重叠层。

  1. 渲染单层时,使用ascii字符。
  2. 渲染多个层时,颜色与下面随机分配的字符和透明填充一起使用。

只有7种颜色(黑色不用于自动分配),因此如果超过7层 如果给定--char标记,则每个标记都必须用于手动分配字符, 表情符号或颜色。

表情符号示例

emoji截图是通过下载 MODIS Landcover dataset,重新采样到25% 它的原始大小转换成一个向量,gdal_polygonize.py, 和split 在执行以下操作之前,在每个类中放入一个ESRI ShapefileQGIS 命令:

$ 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
https://raw.githubusercontent.com/geowurster/gj2ascii/master/images/ascii-land-cover-80w.png

其他示例

有关详细信息,请参见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个像素上渲染各个特征,并显示两个的属性 字段,COUNTYFPNAME

$ 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]

依赖性

对于这样的实用程序来说,依赖关系非常重,可能需要一些 额外的工作来安装所有的东西。所有依赖项都应安装在 拥有但有一些潜在的问题包。手动安装 以下可能有帮助:

一些Linux发行版在安装Rasterio之前需要执行额外的步骤: apt-get install python-numpy-dev libgdal1h libgdal-dev

开发

$ 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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在收到spring mqtt集成中停止重复订阅保留的消息   java改造安卓在textview中显示数据   读取CSV Java时获取While循环中的最后一行数据   将Java程序转换为小程序的部署   java如何在不向Src添加文件的情况下将文件放入GitLab测试   java包含字节数组列表的方法   java十进制转换错误   eclipse是由java引起的。lang.ClassNotFoundException:org。springframework。js。资源ResourceServlet   继承Java向上与向下   java自动调整标签内容的大小   java从Android中的AlertDialog返回信息   java在声明按钮时仿真程序中出现错误   java编写刷新线程的最佳方法   Java初学者错误   java需要帮助重置JComboBox   java如何用Spring/MultipartFile捕获中断流   java是否可以在JUnit中设置被测试类的方法的返回值?