GithubHelp home page GithubHelp logo

geojson-help's Introduction

geojson-help

command line for the GeoJSON format and encode

node npm

安装

$ npm install geojson-help -g

使用

1. 格式转换

$ geo format  -i <input>
  • 默认将arcgis-json插件导出的json文件转换成标准geojson格式,后续扩展其它途径的转换
  • -i参数为需要被转换的json文件的路径,支持glob匹配
  • 默认输出转换后的文件到json_geo文件夹下,文件名保持不变

示例:

$ geo format -i "json/*.json"

注意:-i osx系统,参数值必须为双引号包裹的字符串,未加双引号路径会被预先解析,只能匹配到一个结果;windows下可加可不加,但是别使用单引号,匹配不到的。具体原因不明,有了解的麻烦告诉我。

2. 压缩

使用字符集编码转换和ZigZag算法压缩标准geosjon的几何数据,文件末尾用"UTF8Encoding": true作为标示。结果适用于echarts。也可结合decode解码方法,应用于支持geojson的地图,如leaflet

$ geo encode -i <input>
  • 参数说明同上
  • 转换后输出到json_geo_encode文件夹下

示例:

$ geo encode -i "json_geo/*.json"

3. 解码

针对2.的压缩结果做解码,还原成标准geojson数据。压缩-还原过程,会导致经纬度精度丢失,但一般不影响图层显示。

$ geo decode -i <input>

4.格式化&压缩

连续操作格式化和压缩,其它同上

$ geo transform -i <input>

API

也提供了api接口供运行环境使用

# 安装到项目
npm i geojson-help --save

示例:

import geo from 'geojson-help'
import arcgisjson from '../assets/arcgisjson.json'

var geojson = geo.format(arcgisjson)
var geojsonEncode = geo.encode(geojson)
var geojsonDecode = geo.decode(geojsonEncode)

测试demo

  1. clone 源码到本地, 到该目录执行npm run dev, 打开localhost:9090/demo/index.html, 修改index.htmlrender函数的geojson文件引用,可看结果。
  2. 将文件导入到mapshaper验证。

待扩展

  1. 压缩解码缩放参数
  2. 'format'精度控制,拐点抽稀,进一步提高压缩比。

欢迎提issue

geojson-help's People

Contributors

lefreet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.