source: osm/applications/editors/josm/plugins/seachart/src/s57/S57enc.java@ 31722

Last change on this file since 31722 was 31722, checked in by malcolmh, 10 years ago

[seachart] update

File size: 13.7 KB
Line 
1/* Copyright 2015 Malcolm Herring
2 *
3 * This is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
8 */
9
10package s57;
11
12import java.io.UnsupportedEncodingException;
13import java.util.HashMap;
14import java.util.Map;
15
16import s57.S57dat.*;
17import s57.S57map.*;
18
19public class S57enc { // S57 ENC file generation
20
21 private static byte[] header = {
22 // Record 0
23 '0', '1', '9', '5', '9', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '2', '4', '5', ' ', '!', ' ', '3', '4', '0', '4', // Leader
24 '0', '0', '0', '0', '1', '6', '7', '0', '0', '0', '0', '0', '0', '0', '1', '0', '4', '3', '0', '1', '6', '7', // Directory
25 'D', 'S', 'I', 'D', '1', '6', '5', '0', '2', '1', '0', 'D', 'S', 'S', 'I', '1', '1', '3', '0', '3', '7', '5',
26 'D', 'S', 'P', 'M', '1', '3', '0', '0', '4', '8', '8', 'F', 'R', 'I', 'D', '1', '0', '0', '0', '6', '1', '8',
27 'F', 'O', 'I', 'D', '0', '7', '0', '0', '7', '1', '8', 'A', 'T', 'T', 'F', '0', '5', '9', '0', '7', '8', '8',
28 'N', 'A', 'T', 'F', '0', '6', '8', '0', '8', '4', '7', 'F', 'F', 'P', 'C', '0', '9', '0', '0', '9', '1', '5',
29 'F', 'F', 'P', 'T', '0', '8', '6', '1', '0', '0', '5', 'F', 'S', 'P', 'C', '0', '9', '0', '1', '0', '9', '1',
30 'F', 'S', 'P', 'T', '0', '8', '9', '1', '1', '8', '1', 'V', 'R', 'I', 'D', '0', '7', '8', '1', '2', '7', '0',
31 'A', 'T', 'T', 'V', '0', '5', '8', '1', '3', '4', '8', 'V', 'R', 'P', 'C', '0', '7', '1', '1', '4', '0', '6',
32 'V', 'R', 'P', 'T', '0', '7', '6', '1', '4', '7', '7', 'S', 'G', 'C', 'C', '0', '6', '0', '1', '5', '5', '3',
33 'S', 'G', '2', 'D', '0', '4', '8', '1', '6', '1', '3', 'S', 'G', '3', 'D', '0', '5', '3', '1', '6', '6', '1', 0x1e,
34 // File control field
35 '0', '0', '0', '0', ';', '&', ' ', ' ', ' ',
36 //*** 254
37 '0', 'S', '0', '0', '0', '0', '0', '0', '.', '0', '0', '0', 0x1f, // Filename
38 '0', '0', '0', '1', 'D', 'S', 'I', 'D', 'D', 'S', 'I', 'D', 'D', 'S', 'S', 'I', '0', '0', '0', '1', 'D', 'S', 'P', 'M',
39 '0', '0', '0', '1', 'F', 'R', 'I', 'D', 'F', 'R', 'I', 'D', 'F', 'O', 'I', 'D', 'F', 'R', 'I', 'D', 'A', 'T', 'T', 'F',
40 'F', 'R', 'I', 'D', 'N', 'A', 'T', 'F', 'F', 'R', 'I', 'D', 'F', 'F', 'P', 'C', 'F', 'R', 'I', 'D', 'F', 'F', 'P', 'T',
41 'F', 'R', 'I', 'D', 'F', 'S', 'P', 'C', 'F', 'R', 'I', 'D', 'F', 'S', 'P', 'T', '0', '0', '0', '1', 'V', 'R', 'I', 'D',
42 'V', 'R', 'I', 'D', 'A', 'T', 'T', 'V', 'V', 'R', 'I', 'D', 'V', 'R', 'P', 'C', 'V', 'R', 'I', 'D', 'V', 'R', 'P', 'T',
43 'V', 'R', 'I', 'D', 'S', 'G', 'C', 'C', 'V', 'R', 'I', 'D', 'S', 'G', '2', 'D', 'V', 'R', 'I', 'D', 'S', 'G', '3', 'D', 0x1e,
44 // Record identifier fields
45 '0', '5', '0', '0', ';', '&', ' ', ' ', ' ', 'I', 'S', 'O', ' ', '8', '2', '1', '1', ' ', 'R', 'e', 'c', 'o', 'r', 'd',
46 ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 0x1f, 0x1f, '(', 'b', '1', '2', ')', 0x1e,
47 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f',
48 'i', 'c', 'a', 't', 'i', 'o', 'n', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'E',
49 'X', 'P', 'P', '!', 'I', 'N', 'T', 'U', '!', 'D', 'S', 'N', 'M', '!', 'E', 'D', 'T', 'N', '!', 'U', 'P', 'D', 'N', '!', 'U',
50 'A', 'D', 'T', '!', 'I', 'S', 'D', 'T', '!', 'S', 'T', 'E', 'D', '!', 'P', 'R', 'S', 'P', '!', 'P', 'S', 'D', 'N', '!', 'P',
51 'R', 'E', 'D', '!', 'P', 'R', 'O', 'F', '!', 'A', 'G', 'E', 'N', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'b', '1', '1', ',', 'b',
52 '1', '4', ',', '2', 'b', '1', '1', ',', '3', 'A', ',', '2', 'A', '(', '8', ')', ',', 'R', '(', '4', ')', ',', 'b', '1', '1',
53 ',', '2', 'A', ',', 'b', '1', '1', ',', 'b', '1', '2', ',', 'A', ')', 0x1e,
54 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'S', 't', 'r', 'u', 'c', 't', 'u',
55 'r', 'e', ' ', 'I', 'n', 'f', 'o', 'r', 'm', 'a', 't', 'i', 'o', 'n', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'D', 'S', 'T', 'R',
56 '!', 'A', 'A', 'L', 'L', '!', 'N', 'A', 'L', 'L', '!', 'N', 'O', 'M', 'R', '!', 'N', 'O', 'C', 'R', '!', 'N', 'O', 'G', 'R',
57 '!', 'N', 'O', 'L', 'R', '!', 'N', 'O', 'I', 'N', '!', 'N', 'O', 'C', 'N', '!', 'N', 'O', 'E', 'D', '!', 'N', 'O', 'F', 'A', 0x1f,
58 '(', '3', 'b', '1', '1', ',', '8', 'b', '1', '4', ')', 0x1e,
59 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'P', 'a', 'r', 'a', 'm', 'e', 't',
60 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'H', 'D', 'A', 'T', '!', 'V',
61 'D', 'A', 'T', '!', 'S', 'D', 'A', 'T', '!', 'C', 'S', 'C', 'L', '!', 'D', 'U', 'N', 'I', '!', 'H', 'U', 'N', 'I', '!', 'P',
62 'U', 'N', 'I', '!', 'C', 'O', 'U', 'N', '!', 'C', 'O', 'M', 'F', '!', 'S', 'O', 'M', 'F', '!', 'C', 'O', 'M', 'T', 0x1f,
63 '(', 'b', '1', '1', ',', 'b', '1', '4', ',', '3', 'b', '1', '1', ',', 'b', '1', '4', ',', '4', 'b', '1', '1', ',', '2', 'b',
64 '1', '4', ',', 'A', ')', 0x1e,
65 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I',
66 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D',
67 '!', 'P', 'R', 'I', 'M', '!', 'G', 'R', 'U', 'P', '!', 'O', 'B', 'J', 'L', '!', 'R', 'V', 'E', 'R', '!', 'R', 'U', 'I', 'N', 0x1f,
68 '(', 'b', '1', '1', ',', 'b', '1', '4', ',', '2', 'b', '1', '1', ',', '2', 'b', '1', '2', ',', 'b', '1', '1', ')', 0x1e,
69 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'I',
70 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'A', 'G', 'E', 'N', '!', 'F', 'I', 'D', 'N',
71 '!', 'F', 'I', 'D', 'S', 0x1f, '(', 'b', '1', '2', ',', 'b', '1', '4', ',', 'b', '1', '2', ')', 0x1e,
72 '2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'A',
73 't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f,
74 '(', 'b', '1', '2', ',', 'A', ')', 0x1e,
75 '2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'N',
76 'a', 't', 'i', 'o', 'n', 'a', 'l', ' ', 'A', 't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f,
77 '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f, '(', 'b', '1', '2', ',', 'A', ')', 0x1e,
78 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
79 'o', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ',
80 'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'F', 'F', 'U', 'I', '!', 'F', 'F', 'I', 'X', '!', 'N',
81 'F', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
82 '2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
83 'o', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ',
84 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'L', 'N', 'A', 'M', '!', 'R', 'I', 'N', 'D', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'B', '(',
85 '6', '4', ')', ',', 'b', '1', '1', ',', 'A', ')', 0x1e,
86 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
87 'o', ' ', 'S', 'p', 'a', 't', 'i', 'a', 'l', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ',
88 'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'F', 'S', 'U', 'I', '!', 'F', 'S', 'I', 'X', '!', 'N',
89 'S', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
90 '2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
91 'o', ' ', 'S', 'p', 'a', 't', 'i', 'a', 'l', ' ', 'R', 'e', 'c', 'o', 'r', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ', 'F',
92 'i', 'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S', 'A', 'G', '!', 'M', 'A', 'S', 'K', 0x1f,
93 '(', 'B', '(', '4', '0', ')', ',', '3', 'b', '1', '1', ')', 0x1e,
94 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I', 'd',
95 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!',
96 'R', 'V', 'E', 'R', '!', 'R', 'U', 'I', 'N', 0x1f, '(', 'b', '1', '1', ',', 'b', '1', '4', ',', 'b', '1', '2', ',', 'b', '1',
97 '1', ')', 0x1e,
98 '2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'A', 't',
99 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f,
100 '(', 'b', '1', '2', ',', 'A', ')', 0x1e,
101 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o',
102 'i', 'n', 't', 'e', 'r', ' ', 'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 's', 0x1f, 'V', 'P', 'U', 'I', '!',
103 'V', 'P', 'I', 'X', '!', 'N', 'V', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
104 '2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o',
105 'i', 'n', 't', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S',
106 'A', 'G', '!', 'T', 'O', 'P', 'I', '!', 'M', 'A', 'S', 'K', 0x1f, '(', 'B', '(', '4', '0', ')', ',', '4', 'b', '1', '1', ')',
107 0x1e,
108 '1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'C', 'o', 'n', 't', 'r',
109 'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'C', 'C', 'U', 'I', '!', 'C', 'C', 'I', 'X', '!', 'C', 'C', 'N', 'C', 0x1f, '(',
110 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
111 '2', '2', '0', '0', ';', '&', ' ', ' ', ' ', '2', '-', 'D', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'F',
112 'i', 'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O', '!', 'X', 'C', 'O', 'O', 0x1f, '(', '2', 'b', '2', '4', ')',
113 0x1e,
114 '2', '2', '0', '0', ';', '&', ' ', ' ', ' ', '3', '-', 'D', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'F',
115 'i', 'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O', '!', 'X', 'C', 'O', 'O', '!', 'V', 'E', '3', 'D', 0x1f, '(', '3', 'b', '2',
116 '4', ')', 0x1e,
117
118 // Record 1
119 '0', '0', '1', '6', '7', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '4', '9', ' ', ' ', ' ', '2', '2', '0', '4', // Leader
120 // Directory
121 '0', '0', '0', '1', '0', '3', '0', '0', 'D', 'S', 'I', 'D', '7', '9', '0', '3', 'D', 'S', 'S', 'I', '3', '6', '8', '2', 0x1e,
122 '1', '0', 0x1e, // Field 0001
123 // Field DSID
124 0x0a, 0x01, 0x00, 0x00, 0x00, 0x01,
125 //*** 2017
126 0x00, '0', 'S', '0', '0', '0', '0', '0', '0', '.', '0', '0', '0', 0x1f, // INTU & Filename
127 '1', 0x1f, '0', 0x1f,
128 //*** 2035
129 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // Date x2 (from system)
130 '0', '3', '.', '1', 0x14, 0x1f, 0x1f, 0x01, 0x26, 0x0f, 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', ' ', 'b', 'y', ' ',
131 'O', 'p', 'e', 'n', 'S', 'e', 'a', 'M', 'a', 'p', '.', 'o', 'r', 'g', 0x1f, 0x1e,
132 // Field DSSI
133 0x02, 0x01, 0x02,
134 //*** 2093
135 0x00, 0x00, 0x00, 0x00, // # of meta records (from metas counter)
136 0x00, 0x00, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, // # of geo records (from geos counter)
138 0x00, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, // # of isolated node records (from isols counter)
140 0x00, 0x00, 0x00, 0x00, // # of connected node records (from conns counter)
141 0x00, 0x00, 0x00, 0x00, // # of edge records (from edges counter)
142 0x00, 0x00, 0x00, 0x00, 0x1e,
143
144 // Record 2
145 '0', '0', '0', '6', '8', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '3', '9', ' ', ' ', ' ', '2', '1', '0', '4',
146 '0', '0', '0', '1', '0', '3', '0', 'D', 'S', 'P', 'M', '2', '6', '3', 0x1e,
147 // Field 0001
148 0x02, 0x00, 0x1e,
149 // Field DSPM
150 0x14, 0x01, 0x00, 0x00, 0x00, 0x02, 0x17, 0x17,
151 //*** 2176
152 0x00, 0x00, 0x00, 0x00, // Scale (from meta list)
153 0x01, // Depth units (from meta list)
154 0x01, // Height units (from meta list)
155 0x01, 0x01,
156 (byte)0x80, (byte)0x96, (byte)0x98, 0x00, // COMF=10000000
157 0x0a, // SOMF=10
158 0x00, 0x00, 0x00, 0x1f, 0x1e
159 };
160
161 static final double COMF=10000000;
162 static final double SOMF=10;
163
164 static int idx;
165 static int recs;
166 static int isols;
167 static int conns;
168 static int metas;
169 static int geos;
170 static int rcid;
171
172 public static int encodeChart(S57map map, HashMap<String, String> meta, byte[] buf) throws IndexOutOfBoundsException, UnsupportedEncodingException {
173
174 /*
175 * Encoding order:
176 * 1. Copy records 0-3 & fill in meta attributes.
177 * 2. Depth isolated nodes.
178 * 3. All other isolated nodes.
179 * 4. Connected nodes.
180 * 5. Edges.
181 * 6. Meta objects.
182 * 7. Geo objects.
183 */
184
185 recs = rcid = 3;
186 isols = conns = metas = geos = 0;
187 for (idx = 0; idx < header.length; idx++) {
188 buf[idx] = header[idx];
189 }
190// byte[] file = S57dat.encSubf(S57subf.FILE, meta.get("FILE"));
191
192 for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
193 S57map.Snode node = entry.getValue();
194 if (node.flg == Nflag.ISOL) {
195 byte[] record = S57dat.encRecord(recs++, S57record.VI, rcid++, 1, 1, (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF));
196 System.arraycopy(record, 0, buf, idx, record.length);
197 idx += record.length;
198 isols++;
199 recs++;
200 }
201 }
202
203 return idx;
204}
205
206 public static int encodeCatalogue(S57map map, byte[] buf) throws IndexOutOfBoundsException {
207
208 return idx;
209}
210
211}
Note: See TracBrowser for help on using the repository browser.