46 JSONObject result=
new JSONObject();
47 result.put(
"type",
"Coverage");
48 JSONObject domain=
new JSONObject();
49 result.put(
"domain",domain);
50 domain.put(
"type",
"Domain");
51 domain.put(
"domainType",
"Grid");
52 JSONArray geocoords=
new JSONArray();
53 JSONArray tempcoords=
new JSONArray();
54 JSONObject axes=
new JSONObject();
55 domain.put(
"axes",axes);
56 for(
int i=0;i<
coverage.getGridGeometry().getExtent().getDimension();i++) {
57 if(
coverage.getGridGeometry().getExtent().getAxisType(i).get().equals(DimensionNameType.COLUMN)) {
58 axes.put(
"x",
new JSONObject());
61 else if(
coverage.getGridGeometry().getExtent().getAxisType(i).get().equals(DimensionNameType.ROW)) {
62 axes.put(
"y",
new JSONObject());
65 else if(
coverage.getGridGeometry().getExtent().getAxisType(i).get().equals(DimensionNameType.VERTICAL)) {
66 axes.put(
"z",
new JSONObject());
69 else if(
coverage.getGridGeometry().getExtent().getAxisType(i).get().equals(DimensionNameType.TIME)) {
70 axes.put(
"t",
new JSONObject());
74 JSONArray referencing=
new JSONArray();
75 domain.put(
"referencing", referencing);
76 if(!geocoords.isEmpty()) {
77 JSONObject crs=
new JSONObject();
78 JSONObject tcrs=
new JSONObject();
79 crs.put(
"system",tcrs);
80 crs.put(
"coordinates",geocoords);
82 tcrs.put(
"type",
"GeopraphicCRS");
84 if(
coverage.getCoordinateReferenceSystem()!=
null) {
85 tcrs.put(
"id",
coverage.getCoordinateReferenceSystem().getName());
91 if(!tempcoords.isEmpty()) {
92 JSONObject tcrs=
new JSONObject();
93 JSONObject tcrstype=
new JSONObject();
94 tcrs.put(
"coordinates",
new JSONArray());
95 tcrs.put(
"system",tcrstype);
96 tcrs.put(
"type",
"TemporalRS");
97 tcrs.put(
"calendar",
"Gregorian");
98 referencing.put(tcrs);
103 JSONObject ranges=
new JSONObject();
104 result.put(
"ranges",ranges);
105 JSONObject parameters=
new JSONObject();
106 result.put(
"parameters", parameters);
107 for(SampleDimension dimension:
coverage.getSampleDimensions()) {
108 JSONObject sampledim=
new JSONObject();
109 parameters.put(dimension.getName().toString(),sampledim);
110 JSONObject paramrange=
new JSONObject();
111 ranges.put(dimension.getName().toString(),paramrange);
112 paramrange.put(
"type",
"NdArray");
113 paramrange.put(
"dataType",
"float");
114 JSONArray axiss=
new JSONArray();
115 paramrange.put(
"axisNames",axiss);
116 for(String ax:axes.keySet()) {
119 paramrange.put(
"shape",
new JSONArray());
120 paramrange.put(
"values",
new JSONArray());
121 sampledim.put(
"type",
"Parameter");
122 JSONObject description=
new JSONObject();
123 sampledim.put(
"description",description);
124 description.put(
"en",dimension.getName().toString());
125 if(dimension.getUnits()!=
null && dimension.getUnits().isPresent()) {
126 JSONObject unit=
new JSONObject();
127 sampledim.put(
"unit",unit);
128 JSONObject unitlabel=
new JSONObject();
129 unit.put(
"label",unitlabel);
130 unitlabel.put(
"en",dimension.getUnits().get().getName());
131 JSONObject symbol=
new JSONObject();
132 unit.put(
"symbol",symbol);
133 symbol.put(
"value",dimension.getUnits().get());
135 JSONObject observedProperty=
new JSONObject();
136 sampledim.put(
"observedProperty",observedProperty);
137 JSONObject catencoding=
null;
138 if(dimension.getCategories()!=
null && !dimension.getCategories().isEmpty()) {
139 catencoding=
new JSONObject();
140 JSONArray categories=
new JSONArray();
141 observedProperty.put(
"categories",categories);
142 for(Category cat:dimension.getCategories()) {
143 JSONObject category=
new JSONObject();
144 JSONObject catlabel=
new JSONObject();
145 category.put(
"label",catlabel);
146 catlabel.put(
"en",dimension.getUnits().get().getName());
147 JSONObject catdesc=
new JSONObject();
148 category.put(
"description",catdesc);
149 catdesc.put(
"en",dimension.getUnits().get().getName());
150 categories.put(category);
153 if(catencoding!=
null) {
154 observedProperty.put(
"categoryEncoding",catencoding);
156 JSONObject oPLabel=
new JSONObject();
157 observedProperty.put(
"label",oPLabel);