|
| 1 | +import { Zondy } from '../../common/Base'; |
| 2 | +import BaseQueryParameter from '../ServiceParameter'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @author 创新中心-潘卓然 |
| 6 | + * @class module:PostGIS.PostgisQueryParameter |
| 7 | + * @param {Object} option 查询条件 |
| 8 | + * @param {String} [option.gdbp] 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名) |
| 9 | + * @param {Boolean} [option.includeProperites = true] 查询结果中是否包含属性 |
| 10 | + * @param {String} [option.where] 属性条件 (例如:id>5,id<10) |
| 11 | + * @param {String} [option.fields] 统计计算中用于分组字段名列表 |
| 12 | + * @param {String} [option.geometry] 几何信息,圆、多边形等 |
| 13 | + * @param {String} [option.geoFormat="wkt"] 几何类型,wkt、wkb、geojson、自定义等 |
| 14 | + * @param {String} [option.sref] 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号,其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式,若指定了该参数,则系统认为 geometry 的坐标系为此坐标系 |
| 15 | + */ |
| 16 | +export class PostgisQueryParameter extends BaseQueryParameter { |
| 17 | + constructor(option) { |
| 18 | + super(option); |
| 19 | + /** |
| 20 | + * @member module:PostGIS.PostgisQueryParameter.prototype.gdbp |
| 21 | + * @description 发布在igs上的pg图层gdbp地址,可以从中解析libName(数据库名)、schemas(工作空间名)、tableName(表名) |
| 22 | + * @type String |
| 23 | + */ |
| 24 | + this.gdbp = option.gdbp; |
| 25 | + /** |
| 26 | + * @member module:PostGIS.PostgisQueryParameter.prototype.includeProperites |
| 27 | + * @description 查询结果中是否包含属性 |
| 28 | + * @type Boolean |
| 29 | + * @default true |
| 30 | + */ |
| 31 | + this.includeProperites = option.includeProperites; |
| 32 | + /** |
| 33 | + * @member module:PostGIS.PostgisQueryParameter.prototype.where |
| 34 | + * @description 属性条件 (例如:id>5,id<10) |
| 35 | + * @type String |
| 36 | + */ |
| 37 | + this.where = option.where; |
| 38 | + /** |
| 39 | + * @member module:PostGIS.PostgisQueryParameter.prototype.fields |
| 40 | + * @description 统计计算中用于分组字段名列表 |
| 41 | + * @type String |
| 42 | + */ |
| 43 | + this.fields = option.fields; |
| 44 | + /** |
| 45 | + * @member module:PostGIS.PostgisQueryParameter.prototype.geometry |
| 46 | + * @description 几何信息,圆、多边形等 |
| 47 | + * @type String |
| 48 | + */ |
| 49 | + this.geometry = option.geometry; |
| 50 | + /** |
| 51 | + * @member module:PostGIS.PostgisQueryParameter.prototype.geoFormat |
| 52 | + * @description 几何类型,wkt、wkb、geojson、自定义等 |
| 53 | + * @type String |
| 54 | + */ |
| 55 | + this.geoFormat = option.geoFormat; |
| 56 | + /** |
| 57 | + * @member module:PostGIS.PostgisQueryParameter.prototype.sref |
| 58 | + * @description 动态投影坐标系 ID,支持 MapGIS 和 EPSG 标准编号, |
| 59 | + * 其中 MapGIS 只支持当前库中自带的坐标系的 ID,EPSG 标准请 使用 EPSG:4326 格式, |
| 60 | + * 若指定了该参数,则系统认为 geometry 的坐标系为此坐标系 |
| 61 | + * @type String |
| 62 | + */ |
| 63 | + this.sref = option.sref; |
| 64 | + } |
| 65 | + |
| 66 | + fixParams() { |
| 67 | + const { gdbp, pageNo, pageSize, includeProperites, where, fields, sref } = this; |
| 68 | + const vecStr = gdbp.split('/'); |
| 69 | + if (vecStr.length < 5) return; |
| 70 | + let queryParam = {}; |
| 71 | + queryParam.libName = vecStr[vecStr.length - 5]; |
| 72 | + queryParam.tableName = vecStr[vecStr.length - 1]; |
| 73 | + queryParam.schemas = vecStr[vecStr.length - 5]; |
| 74 | + queryParam.pageNo = pageNo !== undefined ? pageNo : 1; |
| 75 | + queryParam.pageSize = pageSize || 10; |
| 76 | + queryParam.includeProperites = includeProperites; |
| 77 | + queryParam.filter = where; |
| 78 | + queryParam.fields = fields; |
| 79 | + queryParam.sref = sref; |
| 80 | + queryParam.geometry = this.fixGeometry(); |
| 81 | + } |
| 82 | + |
| 83 | + fixGeometry() { |
| 84 | + let { geometry } = this; |
| 85 | + if (geometry) { |
| 86 | + queryParam.geoFormat = 'wkt'; |
| 87 | + const geometryType = geometry.getGeometryType(); |
| 88 | + const arr = []; |
| 89 | + let str; |
| 90 | + if (geometryType === 'rect') { |
| 91 | + arr.push(`${option.geometry.xmin} ${option.geometry.ymin}`); |
| 92 | + arr.push(`${option.geometry.xmin} ${option.geometry.ymax}`); |
| 93 | + arr.push(`${option.geometry.xmax} ${option.geometry.ymax}`); |
| 94 | + arr.push(`${option.geometry.xmax} ${option.geometry.ymin}`); |
| 95 | + arr.push(`${option.geometry.xmin} ${option.geometry.ymin}`); |
| 96 | + } else if (geometryType === 'polygon' || geometryType === 'polygon') { |
| 97 | + const { pointArr } = option.geometry; |
| 98 | + for (let i = 0; i < pointArr.length; i += 1) { |
| 99 | + arr.push(`${pointArr[i].x} ${pointArr[i].y}`); |
| 100 | + } |
| 101 | + str = arr.join(','); |
| 102 | + if (geometryType === 'polygon') { |
| 103 | + queryParam.geometry = `POLYGON(( ${str}))`; |
| 104 | + } else if (geometryType === 'line') { |
| 105 | + queryParam.geometry = `LINESTRING(${str})`; |
| 106 | + } |
| 107 | + } else if (geometryType === 'point') { |
| 108 | + queryParam.geometry = `POINT(${option.geometry.x} ${option.geometry.y})`; |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +export default PostgisQueryParameter; |
| 115 | +Zondy.DataStore.PostGIS.PostgisQueryParameter = PostgisQueryParameter; |
0 commit comments