Skip to content

Commit 159f345

Browse files
committed
v1.6 FeatureCollection增加header属性
1 parent c8ab176 commit 159f345

File tree

14 files changed

+2844
-2373
lines changed

14 files changed

+2844
-2373
lines changed

giscat-vector/giscat-vector-mbexpression/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>giscat-vector</artifactId>
77
<groupId>org.wowtools</groupId>
8-
<version>g1.5.2</version>
8+
<version>g1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>giscat-vector-mbexpression</artifactId>
13-
<version>g1.5.2</version>
13+
<version>g1.6.0</version>
1414
<description>mapbox expressions表达式解析为java对象,用以支持数据过滤等场景</description>
1515

1616
<dependencies>

giscat-vector/giscat-vector-mvt/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>giscat</artifactId>
77
<groupId>org.wowtools</groupId>
8-
<version>g1.5.2</version>
8+
<version>g1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>giscat-vector-mvt</artifactId>
13-
<version>g1.5.2</version>
13+
<version>g1.6.0</version>
1414
<description>Mapbox vector tile (mvt) 的序列化与反序列化</description>
1515

1616
<dependencies>

giscat-vector/giscat-vector-pojo/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>giscat-vector</artifactId>
77
<groupId>org.wowtools</groupId>
8-
<version>g1.5.2</version>
8+
<version>g1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>giscat-vector-pojo</artifactId>
13-
<version>g1.5.2</version>
13+
<version>g1.6.0</version>
1414
<dependencies>
1515
<dependency>
1616
<groupId>org.locationtech.jts</groupId>

giscat-vector/giscat-vector-pojo/src/main/java/org/wowtools/giscat/vector/pojo/FeatureCollection.java

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.wowtools.giscat.vector.pojo;
2121

2222
import java.util.List;
23+
import java.util.Map;
2324

2425
/**
2526
* FeatureCollection
@@ -28,13 +29,29 @@
2829
* @date 2022/3/15
2930
*/
3031
public class FeatureCollection {
32+
/**
33+
* 要素
34+
*/
3135
private List<Feature> features;
3236

37+
/**
38+
* 头信息,可以在headers中添加一些关于FeatureCollection、features等的描述信息
39+
*/
40+
private Map<String, Object> headers;
41+
3342
public List<Feature> getFeatures() {
3443
return features;
3544
}
3645

3746
public void setFeatures(List<Feature> features) {
3847
this.features = features;
3948
}
49+
50+
public Map<String, Object> getHeaders() {
51+
return headers;
52+
}
53+
54+
public void setHeaders(Map<String, Object> headers) {
55+
this.headers = headers;
56+
}
4057
}

giscat-vector/giscat-vector-pojo/src/main/java/org/wowtools/giscat/vector/pojo/GeoJsonObject.java

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public String toGeoJsonString() {
262262
public static final class FeatureCollection {
263263
private final String type = "FeatureCollection";
264264
private Feature[] features;
265+
private Map<String, Object> headers;
265266

266267
@JsonIgnore
267268
public String toGeoJsonString() {

giscat-vector/giscat-vector-pojo/src/main/java/org/wowtools/giscat/vector/pojo/converter/GeoJsonFeatureConverter.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
****************************************************************/
2020
package org.wowtools.giscat.vector.pojo.converter;
2121

22+
import com.fasterxml.jackson.annotation.JsonInclude;
2223
import com.fasterxml.jackson.core.JsonProcessingException;
2324
import com.fasterxml.jackson.databind.JavaType;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -45,6 +46,9 @@ public class GeoJsonFeatureConverter {
4546
* jackson ObjectMapper
4647
*/
4748
public static final ObjectMapper mapper = new ObjectMapper();
49+
static {
50+
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
51+
}
4852

4953
private static final JavaType typeGeometry = mapper.constructType(GeoJsonObject.Geometry.class);
5054
private static final JavaType typeFeature = mapper.constructType(GeoJsonObject.Feature.class);
@@ -102,14 +106,20 @@ public static GeoJsonObject.Feature toGeoJson(Feature feature) {
102106
* @return geojson
103107
*/
104108
public static GeoJsonObject.FeatureCollection toGeoJson(FeatureCollection featureCollection) {
109+
GeoJsonObject.FeatureCollection geoJsonFeatureCollection = new GeoJsonObject.FeatureCollection();
110+
111+
if (null != featureCollection.getHeaders()) {
112+
geoJsonFeatureCollection.setHeaders(featureCollection.getHeaders());
113+
}
114+
105115
GeoJsonObject.Feature[] geoJsonFeatures = new GeoJsonObject.Feature[featureCollection.getFeatures().size()];
106116
int i = 0;
107-
GeoJsonObject.FeatureCollection geoJsonFeatureCollection = new GeoJsonObject.FeatureCollection();
108117
for (Feature feature : featureCollection.getFeatures()) {
109118
geoJsonFeatures[i] = toGeoJson(feature);
110119
i++;
111120
}
112121
geoJsonFeatureCollection.setFeatures(geoJsonFeatures);
122+
113123
return geoJsonFeatureCollection;
114124
}
115125

@@ -218,13 +228,17 @@ public static FeatureCollection fromGeoJsonFeatureCollection(String strGeoJsonFe
218228
* @return FeatureCollection
219229
*/
220230
public static FeatureCollection fromGeoJsonFeatureCollection(GeoJsonObject.FeatureCollection geoJsonFeatureCollection, GeometryFactory geometryFactory) {
231+
FeatureCollection featureCollection = new FeatureCollection();
232+
233+
featureCollection.setHeaders(geoJsonFeatureCollection.getHeaders());
234+
221235
List<Feature> features = new ArrayList<>(geoJsonFeatureCollection.getFeatures().length);
222236
for (int i = 0; i < geoJsonFeatureCollection.getFeatures().length; i++) {
223237
Feature feature = fromGeoJsonFeature(geoJsonFeatureCollection.getFeatures()[i], geometryFactory);
224238
features.add(feature);
225239
}
226-
FeatureCollection featureCollection = new FeatureCollection();
227240
featureCollection.setFeatures(features);
241+
228242
return featureCollection;
229243
}
230244

giscat-vector/giscat-vector-pojo/src/main/java/org/wowtools/giscat/vector/pojo/converter/ProtoFeatureConverter.java

+33-17
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public static byte[] feature2Proto(Feature feature) {
550550
return featureCollection2Proto(fc);
551551
}
552552

553-
private static ProtoFeature.Map.Builder putPropertiesToCell(Map<String, Object> properties,ToProtoKeyValueCell keyValueCell) {
553+
private static ProtoFeature.Map.Builder putPropertiesToCell(Map<String, Object> properties, ToProtoKeyValueCell keyValueCell) {
554554
ProtoFeature.Map.Builder propertiesBuilder = ProtoFeature.Map.newBuilder();
555555
properties.forEach((k, v) -> {
556556
if (null == v) {
@@ -570,23 +570,31 @@ private static ProtoFeature.Map.Builder putPropertiesToCell(Map<String, Object>
570570
* @return ProtoFeature bytes
571571
*/
572572
public static byte[] featureCollection2Proto(FeatureCollection featureCollection) {
573-
ToProtoKeyValueCell keyValueCell = new ToProtoKeyValueCell();//收集key-value与id对应关系
574573
ProtoFeature.FeatureCollection.Builder builder = ProtoFeature.FeatureCollection.newBuilder();
575-
for (Feature feature : featureCollection.getFeatures()) {
576-
//properties转换
577-
Map<String, Object> properties = feature.getProperties();
578-
if (null != properties) {
579-
ProtoFeature.Map.Builder propertiesBuilder = putPropertiesToCell(properties, keyValueCell);
580-
builder.addPropertiess(propertiesBuilder);
581-
} else {
582-
builder.addPropertiess(nullMap);
574+
ToProtoKeyValueCell keyValueCell = new ToProtoKeyValueCell();//收集key-value与id对应关系
575+
//转换头信息
576+
if (null != featureCollection.getHeaders()) {
577+
ProtoFeature.Map.Builder propertiesBuilder = putPropertiesToCell(featureCollection.getHeaders(), keyValueCell);
578+
builder.setHeaders(propertiesBuilder);
579+
}
580+
//转换features
581+
if (null != featureCollection.getFeatures()) {
582+
for (Feature feature : featureCollection.getFeatures()) {
583+
//properties转换
584+
Map<String, Object> properties = feature.getProperties();
585+
if (null != properties) {
586+
ProtoFeature.Map.Builder propertiesBuilder = putPropertiesToCell(properties, keyValueCell);
587+
builder.addPropertiess(propertiesBuilder);
588+
} else {
589+
builder.addPropertiess(nullMap);
590+
}
591+
//geometry转换
592+
Geometry geometry = feature.getGeometry();
593+
ProtoFeature.Geometry.Builder geometryBuilder = geometry2ProtoBuilder(geometry);
594+
builder.addGeometries(geometryBuilder);
583595
}
584-
//geometry转换
585-
Geometry geometry = feature.getGeometry();
586-
ProtoFeature.Geometry.Builder geometryBuilder = geometry2ProtoBuilder(geometry);
587-
builder.addGeometries(geometryBuilder);
588-
589596
}
597+
590598
keyValueCell.toProto(builder);
591599
return builder.build().toByteArray();
592600
}
@@ -988,9 +996,18 @@ public static FeatureCollection proto2featureCollection(byte[] bytes, GeometryFa
988996
} catch (InvalidProtocolBufferException e) {
989997
throw new RuntimeException(e);
990998
}
999+
FeatureCollection featureCollection = new FeatureCollection();
1000+
9911001
//构造Properties 真实值
9921002
FromProtoKeyValueCell keyValueCell = new FromProtoKeyValueCell(pFeatureCollection);
9931003

1004+
//构造headers
1005+
if (pFeatureCollection.hasHeaders()) {
1006+
ProtoFeature.Map pHeaders = pFeatureCollection.getHeaders();
1007+
Map<String, Object> headers = keyValueCell.parseProperties(pHeaders);
1008+
featureCollection.setHeaders(headers);
1009+
}
1010+
9941011
//构造feature
9951012
int featureNum = pFeatureCollection.getGeometriesCount();
9961013
ArrayList<Feature> features = new ArrayList<>(featureNum);
@@ -1007,9 +1024,8 @@ public static FeatureCollection proto2featureCollection(byte[] bytes, GeometryFa
10071024

10081025
features.add(feature);
10091026
}
1010-
1011-
FeatureCollection featureCollection = new FeatureCollection();
10121027
featureCollection.setFeatures(features);
1028+
10131029
return featureCollection;
10141030
}
10151031

0 commit comments

Comments
 (0)