在命令行中将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 Hibernate会话。save()不返回值吗?   java JMS应用程序发布订阅   java使用字符串创建一个长度为n,高度为n的正方形   java如何在MySQL的SQL查询中传递ArrayList<>如IN子句   安卓 java。lang.IllegalArgumentException:指定为非null的参数为null:方法kotlin。jvm。内部的内在的。检查参数不完整   如何用Java绘制交互式图形/线条?   java Blackberry移动Web应用快捷方式   java Json LocalDateTIme问题   java更改密钥的颜色   java在过滤条件之后在流上迭代时如何获取上一个对象   Java:按位和创建无符号字节   java在JavaScript中检索Velocity循环变量   java JButton不会出现在GUI上   java Cell API json转换到POJO   java在模拟中初始化静态最终变量