@mapcatch/util 2.0.1 → 2.0.3-a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/dist/catchUtil.min.esm.js +10781 -10608
- package/dist/catchUtil.min.js +91 -91
- package/package.json +2 -1
- package/src/constants/crs.js +19 -12
- package/src/measure/index.js +12 -1
- package/src/photo-parser/exif/index.js +17 -4
- package/src/photo-parser/index.js +9 -5
- package/src/report/report.js +13 -15
- package/src/transform.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapcatch/util",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3-a",
|
|
4
4
|
"main": "./dist/catchUtil.min.esm.js",
|
|
5
5
|
"repository": "",
|
|
6
6
|
"author": "wanyanyan",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"protocol-buffers-schema": "^3.6.0",
|
|
34
34
|
"regl": "^2.1.0",
|
|
35
35
|
"satellite-geo-calc": "^0.0.7",
|
|
36
|
+
"spark-md5": "^3.0.2",
|
|
36
37
|
"svg-path-commander": "^2.0.10",
|
|
37
38
|
"upng-js": "^2.1.0",
|
|
38
39
|
"uuid": "^9.0.0"
|
package/src/constants/crs.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
export default [
|
|
2
2
|
{
|
|
3
|
-
'type': '
|
|
4
|
-
'
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
'type': 'COMMON',
|
|
4
|
+
'alias': 'Common',
|
|
5
|
+
'title': '常用坐标系',
|
|
6
|
+
'children': [
|
|
7
|
+
{
|
|
8
|
+
'type': 'GEOGCS',
|
|
9
|
+
'title': 'WGS 84',
|
|
10
|
+
'authName': 'EPSG',
|
|
11
|
+
'authCode': 4326,
|
|
12
|
+
'wkt': 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
'type': 'GEOGCS',
|
|
16
|
+
'title': 'China Geodetic Coordinate System 2000',
|
|
17
|
+
'authName': 'EPSG',
|
|
18
|
+
'authCode': 4490,
|
|
19
|
+
'wkt': 'GEOGCS["China Geodetic Coordinate System 2000",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","1024"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4490"]]'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
15
22
|
},
|
|
16
23
|
{
|
|
17
24
|
'type': 'PROJCS',
|
package/src/measure/index.js
CHANGED
|
@@ -160,7 +160,7 @@ class Measurement {
|
|
|
160
160
|
|
|
161
161
|
while (!triangles.length && projs.length) { // 寻找可成功分解的投影平面
|
|
162
162
|
flatCoordinates = projs.shift()
|
|
163
|
-
flatCoordinates.
|
|
163
|
+
flatCoordinates = this._reduceCoordinates(flatCoordinates)
|
|
164
164
|
let edges = []
|
|
165
165
|
flatCoordinates.forEach((coord, index) => {
|
|
166
166
|
if (index === flatCoordinates.length - 1) {
|
|
@@ -193,6 +193,17 @@ class Measurement {
|
|
|
193
193
|
let c = this.getDistance3D([p3, p1])
|
|
194
194
|
return Math.sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a)) / 4
|
|
195
195
|
}
|
|
196
|
+
|
|
197
|
+
_reduceCoordinates (coords) { // 去重
|
|
198
|
+
for(let i = 0;i < coords.length; i++) {
|
|
199
|
+
let nextIndex = i === coords.length - 1 ? 0 : (i + 1)
|
|
200
|
+
if (_.isEqual(coords[i], coords[nextIndex])) {
|
|
201
|
+
coords.splice(i, 1)
|
|
202
|
+
i--
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return coords
|
|
206
|
+
}
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
export default Measurement
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {getData} from './parse_image'
|
|
2
2
|
import {imageSize} from '../image-size'
|
|
3
3
|
import util from './util'
|
|
4
|
+
import SparkMD5 from 'spark-md5'
|
|
4
5
|
|
|
5
6
|
export const getPhotoMetadata = async (file) => {
|
|
6
7
|
let extent = getFileExtent(file)
|
|
@@ -9,7 +10,7 @@ export const getPhotoMetadata = async (file) => {
|
|
|
9
10
|
try {
|
|
10
11
|
data = await _formatMetadata(file)
|
|
11
12
|
} catch(err) {
|
|
12
|
-
|
|
13
|
+
data = await getImageSize(file)
|
|
13
14
|
}
|
|
14
15
|
} else {
|
|
15
16
|
data = await getImageSize(file)
|
|
@@ -20,6 +21,7 @@ export const getPhotoMetadata = async (file) => {
|
|
|
20
21
|
|
|
21
22
|
async function _formatMetadata (file, index = 1) {
|
|
22
23
|
let buffer = await getFileBuffer(file, index)
|
|
24
|
+
let md5 = getMd5(buffer)
|
|
23
25
|
return new Promise((resolve, reject) => {
|
|
24
26
|
getData(buffer, function (img, err) {
|
|
25
27
|
if (err) {
|
|
@@ -35,14 +37,16 @@ async function _formatMetadata (file, index = 1) {
|
|
|
35
37
|
resolve({
|
|
36
38
|
exif, xmp,
|
|
37
39
|
width: exif.PixelXDimension,
|
|
38
|
-
height: exif.PixelYDimension
|
|
40
|
+
height: exif.PixelYDimension,
|
|
41
|
+
md5
|
|
39
42
|
})
|
|
40
43
|
} else {
|
|
41
44
|
getImageSize(file).then(size => {
|
|
42
45
|
resolve({
|
|
43
46
|
exif, xmp,
|
|
44
47
|
width: size.width,
|
|
45
|
-
height: size.height
|
|
48
|
+
height: size.height,
|
|
49
|
+
md5
|
|
46
50
|
})
|
|
47
51
|
})
|
|
48
52
|
}
|
|
@@ -54,9 +58,11 @@ async function getImageSize (file) {
|
|
|
54
58
|
try {
|
|
55
59
|
let buffer = await getFileBuffer(file)
|
|
56
60
|
let size = imageSize(buffer)
|
|
61
|
+
let md5 = getMd5(buffer)
|
|
57
62
|
return {
|
|
58
63
|
width: size.width,
|
|
59
|
-
height: size.height
|
|
64
|
+
height: size.height,
|
|
65
|
+
md5
|
|
60
66
|
}
|
|
61
67
|
} catch (err) {
|
|
62
68
|
return {
|
|
@@ -127,4 +133,11 @@ function getFileSize(file) {
|
|
|
127
133
|
} else {
|
|
128
134
|
return file.size
|
|
129
135
|
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getMd5 (buffer) {
|
|
139
|
+
let spark = new SparkMD5.ArrayBuffer()
|
|
140
|
+
spark.append(buffer)
|
|
141
|
+
let md5 = spark.end()
|
|
142
|
+
return md5
|
|
130
143
|
}
|
|
@@ -5,14 +5,14 @@ import _ from 'lodash'
|
|
|
5
5
|
|
|
6
6
|
export async function parsePhoto (file) {
|
|
7
7
|
let tags = await getPhotoMetadata(file)
|
|
8
|
-
const {width, height, exif, xmp, filesize} = tags
|
|
9
|
-
let imageMetaData = {width, height, filesize}
|
|
8
|
+
const {width, height, exif, xmp, filesize, md5} = tags
|
|
9
|
+
let imageMetaData = {width, height, filesize, md5}
|
|
10
10
|
let lng = NaN, lat = NaN, alt = NaN
|
|
11
11
|
let yaw = NaN, pitch = NaN, roll = NaN
|
|
12
12
|
let x_std = NaN, y_std = NaN, z_std = NaN
|
|
13
13
|
let pos = [lng, lat, alt]
|
|
14
14
|
let flatedXmp = util.flatObject(xmp)
|
|
15
|
-
let {GPSAltitude, GPSLatitude, GPSLatitudeRef, GPSLongitude, GPSLongitudeRef} = exif
|
|
15
|
+
let {GPSAltitude, GPSLatitude, GPSLatitudeRef, GPSLongitude, GPSLongitudeRef} = exif || {}
|
|
16
16
|
if (GPSLongitude && GPSLatitude) {
|
|
17
17
|
pos = [
|
|
18
18
|
util.getGeoCoordOperator(GPSLongitudeRef) * util.toRadian(GPSLongitude),
|
|
@@ -76,10 +76,12 @@ export async function parsePhoto (file) {
|
|
|
76
76
|
imageMetaData.pitch_roll_yaw = [pitch, roll, yaw]
|
|
77
77
|
imageMetaData.orientation = util.getRotationMatrix(pitch, roll, yaw)
|
|
78
78
|
}
|
|
79
|
-
if (exif
|
|
79
|
+
if (exif?.DateTime) {
|
|
80
|
+
imageMetaData.capture_time = moment(exif.DateTime, 'YYYY:MM:DD HH:mm:ss').valueOf()
|
|
81
|
+
} else if (exif?.DateTimeOriginal) {
|
|
80
82
|
imageMetaData.capture_time = moment(exif.DateTimeOriginal, 'YYYY:MM:DD HH:mm:ss').valueOf()
|
|
81
83
|
}
|
|
82
|
-
if (exif
|
|
84
|
+
if (exif?.FocalLengthIn35mmFilm) {
|
|
83
85
|
imageMetaData.focal_length_in_35mm = exif.FocalLengthIn35mmFilm
|
|
84
86
|
}
|
|
85
87
|
if (util.hasNaN(pos)) {
|
|
@@ -154,6 +156,8 @@ export function parsePhotos (files, cb) {
|
|
|
154
156
|
}
|
|
155
157
|
item.fileList.push({
|
|
156
158
|
name: file.split('\\').pop(),
|
|
159
|
+
filesize: meta_data.filesize,
|
|
160
|
+
md5: meta_data.md5,
|
|
157
161
|
filePath: file,
|
|
158
162
|
meta_data
|
|
159
163
|
})
|
package/src/report/report.js
CHANGED
|
@@ -69,6 +69,19 @@ export default async function generateReport (params) {
|
|
|
69
69
|
type: 'cameras',
|
|
70
70
|
items: getCameras(reportInfo)
|
|
71
71
|
},
|
|
72
|
+
{
|
|
73
|
+
type: 'page-line' // 分页
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'sub-title',
|
|
77
|
+
label: '图像位置'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'image',
|
|
81
|
+
imageType: 'photos',
|
|
82
|
+
errorFeatures: await getErrorFeatures(photos, taskInfo, reportInfo),
|
|
83
|
+
errorData: getErrorData(reportInfo.image_POS_diff.filter(d => !!d.pos_diff))
|
|
84
|
+
},
|
|
72
85
|
{
|
|
73
86
|
type: 'page-line' // 分页
|
|
74
87
|
}
|
|
@@ -99,21 +112,6 @@ export default async function generateReport (params) {
|
|
|
99
112
|
}
|
|
100
113
|
// 建了二维地图才有以下报告
|
|
101
114
|
if (tilejson) {
|
|
102
|
-
report.sections[1].content.push(
|
|
103
|
-
{
|
|
104
|
-
type: 'sub-title',
|
|
105
|
-
label: '图像位置'
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
type: 'image',
|
|
109
|
-
imageType: 'photos',
|
|
110
|
-
errorFeatures: await getErrorFeatures(photos, reportInfo, tilejson),
|
|
111
|
-
errorData: getErrorData(reportInfo.image_POS_diff.filter(d => !!d.pos_diff))
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
type: 'page-line' // 分页
|
|
115
|
-
}
|
|
116
|
-
)
|
|
117
115
|
report.sections[2].content.push(
|
|
118
116
|
{
|
|
119
117
|
type: 'sub-title',
|
package/src/transform.js
CHANGED
|
@@ -11,6 +11,9 @@ import { crsList, crsTypes } from './constants'
|
|
|
11
11
|
export function getWKTString (crs) {
|
|
12
12
|
let {type, epsg_code} = crs
|
|
13
13
|
for(let i = 0;i < crsList.length;i++) {
|
|
14
|
+
if (!crsTypes[crsList[i].type]) {
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
14
17
|
let typeCode = crsTypes[crsList[i].type].code
|
|
15
18
|
if (typeCode !== type) {
|
|
16
19
|
continue
|