npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@giszhc/arcgis-to-geojson

v0.0.2

Published

一个轻量级的 ArcGIS JSON 与 GeoJSON 双向转换工具库,支持点、线、面等多种几何类型,开箱即用,并针对现代前端开发进行了 Tree Shaking 优化。

Readme

@giszhc/arcgis-to-geojson

一个轻量级的 ArcGIS JSON 与 GeoJSON 双向转换工具库,支持点、线、面等多种几何类型,开箱即用,并针对现代前端开发进行了 Tree Shaking 优化。

支持以下特性:

  • 双向转换:支持 ArcGIS JSON 转 GeoJSON 和 GeoJSON 转 ArcGIS JSON
  • 几何类型:完整支持 Point、MultiPoint、LineString、MultiLineString、Polygon、MultiPolygon
  • 环处理:自动处理多边形的内外环方向,符合 RFC 7946 和 ArcGIS 标准
  • 坐标验证:智能判断外环与内环的包含关系,正确处理孔洞
  • 要素支持:支持 Feature 和 FeatureCollection 结构,保留属性信息
  • ID 映射:自动识别 OBJECTID、FID 等字段作为要素 ID
  • 坐标系警告:检测非 WGS84 坐标系时发出警告
  • TypeScript:完善的类型定义支持

方法列表

ArcGIS JSON 转 GeoJSON

  • arcgisToGeoJSON - 将 ArcGIS JSON 转换为 GeoJSON 格式

GeoJSON 转 ArcGIS JSON

  • geojsonToArcGIS - 将 GeoJSON 转换为 ArcGIS JSON 格式

在线示例

我们提供了一个功能完整的在线演示页面,您可以直接在浏览器中体验所有功能:

🌐 立即体验: 点击访问在线演示

安装

你可以通过 npm 安装该库:

pnpm install @giszhc/arcgis-to-geojson

使用方法

arcgisToGeoJSON(arcgis: any, idAttribute?: string): any

将 ArcGIS JSON 转换为 GeoJSON 格式。支持点、线、面、要素集合等多种类型。

import { arcgisToGeoJSON } from '@giszhc/arcgis-to-geojson';

// 转换点
const point = {
    x: 116.4,
    y: 39.9
};
const geojson = arcgisToGeoJSON(point);
console.log(geojson);
// { type: 'Point', coordinates: [116.4, 39.9] }

// 转换多边形(带孔洞)
const polygon = {
    rings: [
        [[116.0, 39.0], [117.0, 39.0], [117.0, 40.0], [116.0, 40.0], [116.0, 39.0]],
        [[116.5, 39.5], [116.8, 39.5], [116.8, 39.8], [116.5, 39.8], [116.5, 39.5]]
    ]
};
const geojson2 = arcgisToGeoJSON(polygon);
console.log(geojson2);
// { type: 'Polygon', coordinates: [...] }

// 转换要素集合
const featureCollection = {
    features: [
        {
            geometry: { x: 116.4, y: 39.9 },
            attributes: { name: '北京', OBJECTID: 1 }
        }
    ]
};
const fc = arcgisToGeoJSON(featureCollection);
console.log(fc);
// { type: 'FeatureCollection', features: [...] }

// 指定自定义 ID 字段
const feature = {
    geometry: { x: 116.4, y: 39.9 },
    attributes: { name: '北京', customId: 'BJ001' }
};
const geojson3 = arcgisToGeoJSON(feature, 'customId');
// id: 'BJ001'

geojsonToArcGIS(geojson: any, idAttribute?: string): any

将 GeoJSON 转换为 ArcGIS JSON 格式。自动处理环的方向和坐标系。

import { geojsonToArcGIS } from '@giszhc/arcgis-to-geojson';

// 转换点
const point = {
    type: 'Point',
    coordinates: [116.4, 39.9]
};
const arcgis = geojsonToArcGIS(point);
console.log(arcgis);
// { x: 116.4, y: 39.9, spatialReference: { wkid: 4326 } }

// 转换多边形
const polygon = {
    type: 'Polygon',
    coordinates: [
        [
            [116.0, 39.0], [116.0, 40.0], [117.0, 40.0], [117.0, 39.0], [116.0, 39.0],
            [116.5, 39.5], [116.5, 39.8], [116.8, 39.8], [116.8, 39.5], [116.5, 39.5]
        ]
    ]
};
const arcgis2 = geojsonToArcGIS(polygon);
console.log(arcgis2);
// { rings: [...], spatialReference: { wkid: 4326 } }

// 转换 FeatureCollection
const featureCollection = {
    type: 'FeatureCollection',
    features: [
        {
            type: 'Feature',
            geometry: { type: 'Point', coordinates: [116.4, 39.9] },
            properties: { name: '北京' },
            id: 1
        }
    ]
};
const fc = geojsonToArcGIS(featureCollection);
console.log(fc);
// [{ geometry: {...}, attributes: {...} }]

// 指定自定义 ID 字段名
const feature = {
    type: 'Feature',
    geometry: { type: 'Point', coordinates: [116.4, 39.9] },
    properties: { name: '北京' },
    id: 100
};
const arcgis3 = geojsonToArcGIS(feature, 'FID');
// attributes: { name: '北京', FID: 100 }

注意事项

  1. 坐标系:转换后的 GeoJSON 默认为 WGS84 坐标系(EPSG:4326)。如果 ArcGIS JSON 使用其他坐标系,会发出警告
  2. 环方向
    • ArcGIS:外环顺时针,内环(孔洞)逆时针
    • GeoJSON:外环逆时针,内环(孔洞)顺时针(RFC 7946 标准)
    • 库会自动处理方向转换
  3. ID 映射:默认使用 OBJECTIDFID 作为要素 ID,可通过 idAttribute 参数自定义
  4. 空几何:支持处理空几何体,转换为 null
  5. 三维坐标:支持 Z 坐标(高程)的转换
  6. 多部件几何:自动识别并转换为 MultiPoint、MultiLineString、MultiPolygon