@@ -550,7 +550,7 @@ public static byte[] feature2Proto(Feature feature) {
550
550
return featureCollection2Proto (fc );
551
551
}
552
552
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 ) {
554
554
ProtoFeature .Map .Builder propertiesBuilder = ProtoFeature .Map .newBuilder ();
555
555
properties .forEach ((k , v ) -> {
556
556
if (null == v ) {
@@ -570,23 +570,31 @@ private static ProtoFeature.Map.Builder putPropertiesToCell(Map<String, Object>
570
570
* @return ProtoFeature bytes
571
571
*/
572
572
public static byte [] featureCollection2Proto (FeatureCollection featureCollection ) {
573
- ToProtoKeyValueCell keyValueCell = new ToProtoKeyValueCell ();//收集key-value与id对应关系
574
573
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 );
583
595
}
584
- //geometry转换
585
- Geometry geometry = feature .getGeometry ();
586
- ProtoFeature .Geometry .Builder geometryBuilder = geometry2ProtoBuilder (geometry );
587
- builder .addGeometries (geometryBuilder );
588
-
589
596
}
597
+
590
598
keyValueCell .toProto (builder );
591
599
return builder .build ().toByteArray ();
592
600
}
@@ -988,9 +996,18 @@ public static FeatureCollection proto2featureCollection(byte[] bytes, GeometryFa
988
996
} catch (InvalidProtocolBufferException e ) {
989
997
throw new RuntimeException (e );
990
998
}
999
+ FeatureCollection featureCollection = new FeatureCollection ();
1000
+
991
1001
//构造Properties 真实值
992
1002
FromProtoKeyValueCell keyValueCell = new FromProtoKeyValueCell (pFeatureCollection );
993
1003
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
+
994
1011
//构造feature
995
1012
int featureNum = pFeatureCollection .getGeometriesCount ();
996
1013
ArrayList <Feature > features = new ArrayList <>(featureNum );
@@ -1007,9 +1024,8 @@ public static FeatureCollection proto2featureCollection(byte[] bytes, GeometryFa
1007
1024
1008
1025
features .add (feature );
1009
1026
}
1010
-
1011
- FeatureCollection featureCollection = new FeatureCollection ();
1012
1027
featureCollection .setFeatures (features );
1028
+
1013
1029
return featureCollection ;
1014
1030
}
1015
1031
0 commit comments