Skip to content

OpenGIS 通用工具 API 接口

目录

[toc]

01. 注意事项

  • 该接口为基于开源技术露西娜开发的空间数据处理接口,支持 CMD/HTTP API/引包三种方式调用
  • 特别说明:因前端继续采用 arcgis js api,数据包格式基于沿用 ESRIJSON 格式
  • 下述接口以 CMD 为例进行说明
  • 每调用一次接口均生成一个日志文件,详细记录入参、出参、错误信息

02. 数据标准

2.1. 入参格式标准

json
入参文件:/path/to/input.txt
调用方式:./zt_opengis /path/to/input.txt

2.2. 入参文件格式

json
{
  "exeType": "", //操作指令
  "config": {
    //具体的入参信息
  }
}

2.3. 响应体格式如下

json
{
  "code": 200, //响应码 200 成功  500 失败
  "success": true, //是否成功 true false
  "message": "", //消息描述
  "result": "", //具体的业务数据
  "timestamp": "" //时间戳
}

2.4. ESRI JSON Polyline 格式

json
{
  "feature": {
    "attributes": {
      "OBJECTID": 1,
      "BTID": 1,
      "NAME": "NOTNAMED",
      "LAT": 28,
      "LONG": -94.8,
      "WIND_KTS": 80,
      "PRESSURE": 0,
      "CAT": "H1",
      "BASIN": "North Atlantic",
      "TRACK_DATE": -3740169600000,
      "Shape_Length": 0.600000000000023
    },
    "geometry": {
      "paths": [
        [
          [-94.7999999999999, 28.0000000000001],
          [-95.3999999999999, 28.0000000000001]
        ]
      ]
    }
  }
}

2.5. ESRI JSON Polygon 格式

json
{
  "geometry": {
    "rings": [
      [
        [-97.06138, 32.837],
        [-97.06133, 32.836],
        [-97.06124, 32.834],
        [-97.06127, 32.832],
        [-97.06138, 32.837]
      ],
      [
        [-97.06326, 32.759],
        [-97.06298, 32.755],
        [-97.06153, 32.749],
        [-97.06326, 32.759]
      ]
    ],
    "spatialReference": { "wkid": 4326 }
  },
  "attributes": {
    "OWNER": "Joe Smith",
    "VALUE": 94820.37,
    "APPROVED": true,
    "LASTUPDATE": 1227663551096
  }
}

2.6. ESRI JSON Point 格式

json
{
  "geometry": {
    "x": -118.15,
    "y": 33.8
  },
  "attributes": {
    "OWNER": "Joe Smith",
    "VALUE": 94820.37,
    "APPROVED": true,
    "LASTUPDATE": 1227663551096
  }
}

2.7. geometryType 取值范围

esriGeometryPoint
esriGeometryPolyline
esriGeometryPolygon
esriGeometryMultipoint
esriGeometryEnvelope

2.8. spatialRel 拓扑关系取值范围

esriSpatialRelIntersects
esriSpatialRelContains
esriSpatialRelCrosses
esriSpatialRelEnvelopeIntersects
esriSpatialRelIndexIntersects
esriSpatialRelOverlaps
esriSpatialRelTouches
esriSpatialRelWithin
esriSpatialRelRelation

2.9. 关于 workspace workspaceType 的取值说明

json
**postgresql数据库下的SDE:postgresql
{
    "server": "192.168.3.202",
    "instance": "sde:postgresql:192.168.3.202",
    "database": "gis_data_ntssgh_sde",
    "user": "sde",
    "password": "Qq123456"
}


gdb、mdb、shape、cad的workspace皆为:
{
    "filePath": ""
}

2.10. 关于坐标系 sr 取值的说明

json
厦门92:xiamen92
国家2000:cgcs2000

03. 文件转换接口

3.1. 文件转 JSON

说明

  • 支持的文件有:cad/shape/mdb/gdb
  • shape、gdb 为压缩包格式,支持 rar/zip,支持多级嵌套目录

入参

json
{
  "exeType": "OPENGIS_FILE2JSON",
  "config": {
    "filePath": "" //文件路径shape、gdb为压缩包格式
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123456789,
  "data": [
    {
      "sr": "", //坐标系名称
      "layerName": "", //图层名称
      "features": [
        {
          "layerName": "", //图层名称
          "geometryType": "", //几何类型
          "geometry": [], //图斑
          "attributes": {
            //属性
            "OBJECTID": 1
          }
        }
      ]
    }
  ]
}

3.2. JSON 转 文件

说明

  • 支持的转换成的文件有:cad/shape/mdb/gdb
  • shape、gdb 为压缩包格式提供,支持 rar/zip
  • shape/mdb/gdb 自动赋坐标系信息
  • 自动依据字段配置制定字段类型

字段配置

json

入参

json
{
  "exeType": "OPENGIS_JSON2FILE",
  "config": {
    "fileType": "cad,shape,mdb,gdb",
    "data": [
      {
        "sr": "", //坐标系名称
        "layerName": "", //图层名称
        "features": [
          {
            "layerName": "", //图层名称
            "geometryType": "", //几何类型
            "geometry": [], //图斑
            "attributes": {
              //属性
              "OBJECTID": 1
            }
          }
        ],
        "fields":[//通用字段配置
          {
            "name":"",
            "comment":"",
            "type":""//字段类型,取值范围:XXX TODO
          }
        ]
      }
    ]
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123456789,
  "result": {
    "filePath": "" //文件路径shape、gdb为压缩包格式
  }
}

3.3. 数据库转文件

说明

  • 从数据库中导出图斑为 MDB SHAPE CAD GDB JSON 文件
  • 若 where 不存在、或者为空、或者为空字符串则不处理该参数
  • 若 geometry 不存在、或者为空、或者为空字符串则不处理该参数
  • 若两者都无效,则导出整个图层
  • 工作空间仅支持 gdb/pg

入参

json
{
  "exeType": "OPENGIS_DB2FILE",
  "config": {
    "source": [
      {
        "workSpaceType": "", //工作空间类型gdb/pg
        "workSpace": "",
        "layerName": "", //图层名称
        "where": "", //属性过滤要导出的数据
        "spatialRel": "esriSpatialRelIntersects", //几何拓扑关系
        "geometryType": "esriGeometryPolygon", //通过几何位置和拓扑关系过滤需要导出的数据,为ESRIJSON格式
        "geometry": "" //通过几何位置和拓扑关系过滤需要导出的数据,为ESRIJSON格式
      }
    ],
    "files": [
      {
        "fileType": "cad", //文件类型:cad、shape、mdb、gdb、json
        "filePath": "" //文件路径,若提供该文件路径则按照该文件生成,若为提供则由程序自动生成
      }
    ]
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": [
    {
      "fileType": "cad", //文件类型:cad、shape、mdb
      "filePath": "" //文件路径,
    }
  ]
}

04. 数据编辑

4.1. 数据编辑-JSON 方式

说明

  • JSON 的方式编辑图层要素
  • 支持新增、编辑、删除操作

入参

json
{
  "exeType": "OPENGIS_EDIT_JSON",
  "config": {
    "workSpaceType": "",
    "workSpace": "",
    "layerName": "", //图层名称
    "geometryType": "esriGeometryPolygon",
    "data": {
      "adds": [
        //新增图斑
        {
          "geometry": {
            "rings": [[[64286.686, 11359.276]]]
          },
          "attributes": {
            "BSM": "TX2019090366"
          }
        }
      ],
      "updates": [
        //编辑图斑
        {
          "geometry": {
            "rings": [[[64286.686, 11359.276]]]
          },
          "attributes": {
            "OBJECTID": "",
            "BSM": "TX2019090366"
          }
        }
      ],
      "deletes": "BSM='123123123'" //删除图斑
    }
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "addResults": [
      {
        "OID": 6854,
        "success": true
      }
    ],
    "updateResults": [
      {
        "OID": 6854,
        "success": true
      }
    ],
    "deleteResults": [
      {
        "OID": 6854,
        "success": true
      }
    ]
  }
}

4.2. 数据编辑-编辑-CAD 方式

说明

  • CAD 的方式编辑图层要素
  • 支持新增、编辑操作

入参

json
{
  "exeType": "OPENGIS_EDIT_CAD",
  "config": {
    "mode": "add", //add / edit(若为该值targetWhere无效)
    "geometryType": "esriGeometryPolygon", //只处理指定几何类型的CAD中的数据
    "srcCadFilePath": "", //CAD文件路径,若srcCadFilePath为空则只编辑属性
    "srcCadLayerName": "XZDB,XZDX,XZDS", //以英文逗号分隔,只处理srcCadLayerName中的图层,若为空则导入所有图层数据
    "srcAttributes": {
      //属性,只处理标签在库中存在的属性,若srcAttributes为空则只编辑空间位置
      "SBH": ""
    },
    "targetWorkSpaceType": "",
    "targetWorkSpace": "",
    "targetLayerName": "CH_DJ_XZZD_R", //要编辑的图层
    "targetWhere": "OBJECTID=100" //查询条件(查找出要编辑的要素),若未能查询到数据或者查询到多条数据,则报错且不予处理
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "adds": [
      //新增图斑
      {
        "geometry": {
          "rings": [[[64286.686, 11359.276]]]
        },
        "attributes": {
          "BSM": "TX2019090366"
        }
      }
    ],
    "updates": [
      //编辑图斑
      {
        "geometry": {
          "rings": [[[64286.686, 11359.276]]]
        },
        "attributes": {
          "OBJECTID": "",
          "BSM": "TX2019090366"
        }
      }
    ]
  }
}

4.3. 数据编辑-编辑-数据库

说明

  • 数据编辑操作
  • 当 mode 为 add 时,为新增操作
  • 当 mode 为 edit 时,为编辑操作,通过 srcBsmField 与 targetBsmField 进行匹配,若数据存在则执行图形和属性的编辑更新,若不存在则不予操作
  • 当 mode 为 add 时,为编辑或新增操作,通过 srcBsmField 与 targetBsmField 进行匹配,若数据存在则执行图形和属性的编辑更新,若不存在则执行新增操作
  • 自动按照字段名称匹配属性,若匹配不到对应的字段则不更新

入参

json
{
  "exeType": "OPENGIS_EDIT_DB", //从工作空间中编辑
  "config": {
    "mode": "add", //模式:add、edit
    "geometryType": "esriGeometryPolygon", //只处理指定几何类型的数据
    "sr": "cgcs2000",
    "srcWorkSpaceType": "", //源数据工作空间类型,支持gdb/pg
    "srcWorkSpace": "", //源数据工作空间
    "srcLayerName": "", //源数据图层名称
    "srcWhere": "", //通过查询条件过滤出所需要的参考几何位置,若为空则不过滤
    "srcBsmField": "", //唯一标识字段,在mode为edit用到
    "targetWorkSpaceType": "", //目标数据工作空间类型,支持gdb/pg
    "targetWorkSpace": "",
    "targetLayerName": "", //目标图层
    "targetBsmField": "" //唯一标识字段,在mode为edit用到
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "adds": [
      //新增图斑
      {
        "geometry": {
          "rings": [[[64286.686, 11359.276]]]
        },
        "attributes": {
          "BSM": "TX2019090366"
        }
      }
    ],
    "updates": [
      //编辑图斑
      {
        "geometry": {
          "rings": [[[64286.686, 11359.276]]]
        },
        "attributes": {
          "OBJECTID": "",
          "BSM": "TX2019090366"
        }
      }
    ]
  }
}

4.4. 数据编辑-删除

说明

删除空间数据

入参

json
{
  "exeType": "OPENGIS_DEL_DB",
  "config": {
    "workSpaceType": "", //支持gdb/pg
    "workSpace": "",
    "data": [
      {
        "layerName": "CH_DJ_XZZD_R", //目标图 层
        "where": "OBJECTID=100" //根据查询条件删除数据
      }
    ]
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": ""
}

04. 空间分析

4.1. 面积、长度计算

说明

  • 计算几何要素的长度和面积
  • 单位:平方米

入参

json
{
  "exeType": "OPENGIS_AREA_LENGTHS",
  "config": {
    "sr": "xiamen92",
    "features": [
      {
        "bsm": "", //要素标识码
        "geometryType": "", //esriGeometryPolyline/esriGeometryPolygon
        "geometry": []
      }
    ]
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": [
    {
      "bsm": "", //对应入参的几何要素的标识码
      "area": 123.123, //面积,平方米为单位,在geometryType=esriGeometryPolygon,该值有效
      "lengths": 12.123 //面积,米为单位
    }
  ]
}

4.2.验证是否闭合、自相交

说明

  • 验证图形是否闭合、是否自相交

入参

json
{
  "exeType": "OPENGIS_ISBH_ISZXJ",
  "config": {
    "files": [
      {
        "bsm": "", //文件标识码
        "fileUrl": "" //txt文件类型
      }
    ]
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "files": [
      {
        "bsm": "", //文件标识码
        "isClosed": true, //是否闭合 取值范围 true、false
        "isSelfIntersecting": false // 是否自相交 取值范围true、false
      }
    ]
  }
}

txt 文件内容格式

  • txt 内容的格式一:
1,24°27′03.8660″,118°3′54.3190″,1
2,24°27′03.8690″,118°3′54.3340″,1
3,24°27′03.8480″,118°3′54.4190″,1
4,24°27′03.7930″,118°3′54.5370″,1
5,24°27′03.8060″,118°3′54.7370″,1
6,24°27′03.7470″,118°3′55.2610″,1
7,24°27′03.6750″,118°3′55.6760″,1
8,24°27′03.8440″,118°3′58.8070″,1
9,24°27′03.8460″,118°3′58.8170″,1
10,24°27′03.8510″,118°3′58.8250″,1
11,24°27′04.2250″,118°3′54.1140″,1
12,24°27′03.1610″,118°3′59.1940″,2
13,24°27′03.1390″,118°3′59.4690″,2
14,24°27′03.3150″,118°3′59.1150″,2
15,24°27′03.2740″,118°3′59.1620″,2
16,24°27′03.1830″,118°3′59.1920″,2
17,24°27′05.1600″,118°3′53.5860″,3
18,24°27′04.7950″,118°3′58.1870″,3
19,24°27′04.8440″,118°3′58.2650″,3
20,24°27′05.3080″,118°3′54.3940″,3
21,24°27′05.3160″,118°3′53.9150″,3
22,24°27′05.5370″,118°3′53.7220″,3
23,24°27′05.4310″,118°3′53.7820″,3
24,24°27′05.2940″,118°3′53.5110″,3
  • txt 内容的格式二:
json
{
  "geometry": {
    "rings": [
      [
        [-97.06138, 32.837],
        [-97.06133, 32.836],
        [-97.06124, 32.834],
        [-97.06127, 32.832],
        [-97.06138, 32.837]
      ],
      [
        [-97.06326, 32.759],
        [-97.06298, 32.755],
        [-97.06153, 32.749],
        [-97.06326, 32.759]
      ]
    ],
    "spatialReference": { "wkid": 4326 }
  },
  "attributes": {
    "OWNER": "Joe Smith"
  }
}

4.3. 空间分析-数据库

说明

  • 仅支持面图层的叠加分析
  • targetWorkSpaceType 仅支持 gdb/pg
  • srcWorkSpaceType 为 json 时,json 为几何类型 esriGeometryPolygon 的 esrijson 格式

入参

json
{
  "exeType": "OPENGIS_ANALYSIS", //空间分析支持厦门92 CSCS2000坐标系,仅实现针对面要素的叠加分析
  "config": {
    "sr": "cscs2000",
    "source": {
      "srcWorkSpaceType": "", //参考几何位置所在工作空间类型 gdb/pg/json(若为该值,则srcLayerName、srcWhere无效)
      "srcWorkSpace": "", //参考几何位置所在工作空间类型
      "srcLayerName": "", //参考几何位置所在图层名称
      "srcWhere": "" //通过查询条件过滤出所需要的参考几何位置,若为空则不过滤
    },
    "target": {
      "targetWorkSpaceType": "", //目标工作空间 gdb/pg
      "targetWorkSpace": "",
      "layers": [
        {
          "targetLayerName": "", //目标图层
          "targetWhere": "" //通过查询条件过滤出所需要的参考几何位置,若为空则不过滤
        }
      ]
    }
  }
}

响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "topologyInfos": [{ //分析出的拓扑信息
        "targetLayerName":"",
        "targetWhere": "",
        "oid": int, //分析出的要素oid
        "sourceGeo": string, //原始图形geometryJson
        "targetGeo": string, //分析出的要素的geometryJson
        "intersectGeo": string, //相交部分的geometryJson
        "differenceGeo": string, //未相交部分的geometryJson
        "sourceArea": double,//原始图形面积
        "targetGeoArea": double, //目标图形面积
        "intersectArea": double, //相交部分面积
        "differenceArea": double, //未相交部分面积
        "isContains": bool, //geometry是否包含targetGeo
        "isWithin": bool, //geometry是否被targetGeo包含
        "isEquals": bool, //geometry与targetGeo是否完全相等
         "attributes": {
            "key": value,
             ...
          }
      }
    ]
  }
}

4.4. 坐标转换

说明

  • 支持转换的坐标系 CSCS2000、XM92、XA80
  • 支持的转换方向有:
  • XM92toCGCS2000 厦门92转国家2000坐标系
  • CGCS2000toXM92 国家2000坐标系转厦门92坐标系
  • XM92toXA80 厦门92转西安80坐标系
  • XA80toXM92 西安80坐标系转厦门92坐标系
  • XM80_PRJ 西安80坐标系球面与平面互转
  • CGCS2000_PRJ 国家2000坐标系球面与平面互转
  • XM92_PRJ 厦门92坐标系球面与平面互转

1. 入参

json
{
  "exeType": "SR_TRANSFORM",
  "config": {
    "direction": "XM92toCGCS2000",
    "inputPara": {
      "isBig92": true, //输入是否为大92坐标(支持的坐标系:XM92)
      "isHave39": true, //输入带有39度带号坐标(支持的坐标系:CGCS2000、西安80)
      "isLatLon": true, ///输出是否为经纬度坐标,若isLatLon=true则isHave39不可用
      "columnIndexX": 1, //x坐标列索引,对于数据类型为xls,xlsx,cvs,txt时,需指定
      "columnIndexY": 2 //y坐标列索引,对于数据类型为xls,xlsx,cvs,txt时,需指定
    },
    "outputPara": {
      "isBig92": true, //输出是否为大92坐标(支持的坐标系:XM92)
      "isHave39": true, //输出带有39度带号坐标(支持的坐标系:CGCS2000、西安80)
      "isLatLon": true //输出是否为经纬度坐标,若isLatLon=true则isHave39不可用
    },
    "dataType": "file", //file 文件、json文本
    "fileType": "shp", //文件类型,当dataType为file时必填,支持的文件类型有:dwg,dxf,gdb,shp,mdb,xls,xlsx,csv,txt,json
    "file": "文件路径", //dataType=file时采用
    "fileName": "原文件名称" //dataType=file时采用,如为空,取文件路径的文件名称
  }
}


- //dataType=json时采用该格式
[
  {
    "X": 64669.881,
    "Y": 30067.315,
    "tag": "1811517"
  }
]

2. 响应体

json
{
  "code": 200,
  "success": true,
  "message": "",
  "timestamp": 123123123,
  "result": {
    "source": {
      "layerName": "",
      "geometryType": "",
      "features": [
        {
          "geometry": []
        }
      ]
    },
    "transformType": "cscs2000pmTOcscs2000qm" //转换操作
  }
}