# @graphile/postgis 中文文档

规范地址：https://npmcn.com/package/%40graphile/postgis/

版本：0\.2\.0
npm 元数据更新时间：2023-04-19T08:37:03.522Z
中文译文更新时间：2026-11-17T00:28:29.850Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40graphile/postgis
原文对照：https://npmcn.com/package/%40graphile/postgis/?lang=original
项目主页：https://github.com/graphile/postgis#readme
源码仓库：https://github.com/graphile/postgis

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：70.7 kB，53 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：graphile-build ^4\.4\.0，graphile-build-pg ^4\.4\.0，graphql \>=0\.6 \<16，pg-sql2 \>=2\.2\.1 \<5
- 首次发布：2019-03-08T15:21:30.971Z
- 最新版本发布：2023-04-19T08:37:03.379Z
- 近 30 天下载量：15649（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 0 个）

## 中文简介

PostGIS 对 PostGraphile 的支持

## 安装

```sh
npm install @graphile/postgis
```

也可以使用：`pnpm add @graphile/postgis`、`yarn add @graphile/postgis`、`bun add @graphile/postgis`

## README

# @ graphile/ postgis (英语)

这是一个 [Graphile 后图 插件](https://www.graphile.org/postgraphile/extending/) 提供 对大众的支持 [后地理信息系统](http://postgis.net/) 空间数据库 系统.

创建一个 [邮递SQL](https://www.postgresql.org/) 带有 PostGIS 的数据库 列, 运行 [后图形](https://www.graphile.org/postgraphile/) 用这个 插件,并具有充分功能的地理空间意识 [图QL](http://graphql.org/) 您数据库的 API .

## 路线图

工作正在进行中,计划如下:

-   [x] 只读支持 `geojson` 来自所有地理类型的字段(通过共享GraphQL接口)
-   [x] 为所有预期地理类型添加图QL类型( 执行此接口)
-   [x] 只读支持用于确定列的几何子类型并直接曝光(而不是界面)
-   [x] 只读支持 `longitude` 财务报告和审定财务报表 `latitude` 打开 `geography(POINT)` 栏
-   [x] 仅读支持查看列表 `geometries` 在一个 `geography(GEOMETRYCOLLECTION)`
-   [x] 对点列表只读支持( E)`longitude` 财务报告和审定财务报表 `latitude`继续 `geography(LINESTRING)` 财务报告和审定财务报表 `geography(POLYGON)` 栏
-   [x] 创建/更新/null支持 `geography(POINT)` 栏
-   [x] 创建/更新/null支持 `geography(LINESTRING)` 财务报告和审定财务报表 `geography(POLYGON)` 栏
-   [x] 与 `postgraphile-plugin-connection-filter` 以启用 PostGIS 特定过滤(通过) [邮资-插件-连接-过滤-邮资](https://github.com/mattbretl/postgraphile-plugin-connection-filter-postgis/)(中文(简体) )
-   [ ] 对计算属性的只读支持 `geography(LINESTRING)` 财务报告和审定财务报表 `geography(POLYGON)`,例如 `area`, (中文(简体) ), `length`, (中文(简体) ), `perimeter`,以及 `centroid` - 目前可以添加插件并直接消耗GeoJSON.

此插件可以支持许多, 许多其他特性 - 如果您 有具体需要 请联系!

## 使用量

此插件需要 PostGraphile **页:1** 或更高级以正确运行.

添加 PostGIS 到您的数据库 :

```sql
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
```

装入插件 :

```
postgraphile --append-plugins @graphile/postgis
```

#### 查询和变异

以本表为例:

```sql
CREATE TABLE data (
  id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
  geom_point geometry(Point, 4326) default null
);
```

单位 **查询** `geom_point` 以类型表示 `GeometryPoint`示例:

```graphql
query {
  allDatas {
    nodes {
      geomPoint {
        geojson
        srid
        x
        y
      }
    }
  }
}
```

单位 **变异** `geom_point` 以类型表示 `GeoJSON`示例:

```graphql
mutation ($id: UUID!, $geomPoint: GeoJSON!) {
  updateDataById(
    input: {
      id: $id,
      dataPatch: {
        geomPoint: $geomPoint
      }
    }
  ) { ... }
}
```

使用这些变量:

```json
{
  "id": "0116254a-0146-11ea-8418-4f89d6596247",
  "geomPoint": {
    "type": "Point",
    "coordinates": [8.5, 47.5]
  }
}
```

当心2016年以来 `GeoJSON` spec预计坐标为SRID 4326/WGS84(见 [https://tools.ietf.org/html/rfc7946# 第4节](https://tools.ietf.org/html/rfc7946#section-4)) (中文(简体) ). 所以添加一个 `crs` 字段到 GeoJSON 已贬值。 因此,由于v3 PostGIS 将乐于收到GeoJSON之上.

**在较早的版本中, PostGIS 期望通过 SRID**。因此变量是:

```json
{
  "id": "0116254a-0146-11ea-8418-4f89d6596247",
  "geomPoint": {
    "type": "Point",
    "coordinates": [8.5, 47.5],
    "crs": {
      "type": "name",
      "properties": {
        "name": "urn:ogc:def:crs:EPSG::4326"
      }
    }
  }
}
```

## 发展

捐款是极受欢迎的! 要开始, 复制下来的重播, 然后:

```
createdb graphile_test
export TEST_DATABASE_URL=postgres://localhost:5432/graphile_test
yarn
yarn dev
```

注意开发服务器运行于 http://localhost:5123/graphiql

为了进行测试:

```
yarn test
```

## 常见问题

### @graphile/postgis 是什么？

PostGIS 对 PostGraphile 的支持

### 如何安装 @graphile/postgis？

在项目目录运行 npm install @graphile/postgis，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：graphile-build（^4\.4\.0）、graphile-build-pg（^4\.4\.0）、graphql（\>=0\.6 \<16）、pg-sql2（\>=2\.2\.1 \<5）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @graphile/postgis 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @graphile/postgis 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @graphile/postgis 可以商用吗？

@graphile/postgis 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @graphile/postgis 的下载量有多少？

根据 npm 官方下载统计，@graphile/postgis 在 2026/10/17 – 2026/11/15 这 30 天内被下载 15,649 次，日均约 522 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @graphile/postgis 还在维护吗？

最新版本 0\.2\.0 发布于 2023/04/19（3 年前）；至今共发布 9 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/03/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

