Skip to content

Commit

Permalink
ProtoFeature扩充,属性中支持数据、对象、数组与对象的相互嵌套
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmiao committed Oct 28, 2022
1 parent b1d1db0 commit 54e5f86
Show file tree
Hide file tree
Showing 11 changed files with 14,271 additions and 10,326 deletions.
4 changes: 2 additions & 2 deletions giscat-vector/giscat-vector-mbexpression/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>giscat-vector</artifactId>
<groupId>org.wowtools</groupId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>giscat-vector-mbexpression</artifactId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
<description>mapbox expressions表达式解析为java对象,用以支持数据过滤等场景</description>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public void decision() {
Assert.assertEquals(false,
getValue(feature, "[\"any\", false,false,false]")
);
//case
Assert.assertEquals(1,
getValue(feature, "[\"case\", true,1,0]")
);
Assert.assertEquals(2,
getValue(feature, "[\"case\", false,1,true,2,0]")
);
Assert.assertEquals(0,
getValue(feature, "[\"case\", false,1,false,2,0]")
);
//==
Assert.assertEquals(true,
getValue(feature, "[\"==\", 1.0,1.0]")
Expand Down
4 changes: 2 additions & 2 deletions giscat-vector/giscat-vector-mvt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>giscat</artifactId>
<groupId>org.wowtools</groupId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>giscat-vector-mvt</artifactId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
<description>Mapbox vector tile (mvt) 的序列化与反序列化</description>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions giscat-vector/giscat-vector-pojo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>giscat-vector</artifactId>
<groupId>org.wowtools</groupId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>giscat-vector-pojo</artifactId>
<version>1.4.0-STABLE</version>
<version>g1.5.0</version>
<dependencies>
<dependency>
<groupId>org.locationtech.jts</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/
public class ProtoFeatureConverter {

private static final ProtoFeature.NullGeometry nullGeometry = ProtoFeature.NullGeometry.getDefaultInstance();

/**
* geometry 转 ProtoFeature bytes
*
Expand All @@ -49,7 +51,9 @@ public static byte[] geometry2Proto(Geometry geometry) {

private static ProtoFeature.Geometry.Builder geometry2ProtoBuilder(Geometry geometry) {
ProtoFeature.Geometry.Builder geometryBuilder = ProtoFeature.Geometry.newBuilder();
if (geometry instanceof Point) {
if (null == geometry) {
geometryBuilder.setNullGeometry(nullGeometry);
} else if (geometry instanceof Point) {
geometryBuilder.setPoint(point2Proto((Point) geometry));
} else if (geometry instanceof LineString) {
geometryBuilder.setLineString(lineString2Proto((LineString) geometry));
Expand Down Expand Up @@ -262,6 +266,10 @@ private static ProtoFeature.GeometryCollection.Builder geometryCollection2Proto(
ProtoFeature.GeometryCollection.Builder builder = ProtoFeature.GeometryCollection.newBuilder();
for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
Geometry geometry = geometryCollection.getGeometryN(i);
// geometryCollection中不允许null,所以这个检查可以跳过
// if (null == geometry) {
// continue;
// }
if (geometry instanceof Point) {
builder.addPoints(point2Proto((Point) geometry));
} else if (geometry instanceof LineString) {
Expand Down Expand Up @@ -333,6 +341,9 @@ private static Geometry proto2Geometry(ProtoFeature.Geometry pGeometry, Geometry
ProtoFeature.GeometryCollection pGeometryCollection = pGeometry.getGeometryCollection();
return proto2GeometryCollection(pGeometryCollection, geometryFactory);
}
if (pGeometry.hasNullGeometry()) {
return null;
}
throw new RuntimeException("解析pGeometry逻辑错误");
}

Expand Down Expand Up @@ -516,6 +527,24 @@ private static GeometryCollection proto2GeometryCollection(ProtoFeature.Geometry
return geometryFactory.createGeometryCollection(geometries);
}

/**
* Feature 转 ProtoFeature bytes
*
* @param feature
* @return ProtoFeature bytes
*/
public static byte[] feature2Proto(Feature feature) {
ProtoFeature.Feature.Builder builder = ProtoFeature.Feature.newBuilder();
builder.setGeometry(geometry2ProtoBuilder(feature.getGeometry()));

List<ProtoFeature.KeyValue.Builder> keyValueBuilders = new ArrayList<>(feature.getProperties().size());
feature.getProperties().forEach((k, v) -> {

});

return builder.build().toByteArray();
}

/**
* FeatureCollection 转 ProtoFeature bytes
*
Expand All @@ -538,11 +567,9 @@ public static byte[] featureCollection2Proto(FeatureCollection featureCollection
}
//geometry转换
Geometry geometry = feature.getGeometry();
if (null == geometry) {
throw new RuntimeException("geometry不能为空");
}
ProtoFeature.Geometry.Builder geometryBuilder = geometry2ProtoBuilder(geometry);
builder.addGeometries(geometryBuilder);

}
keyValueCell.toProto(builder);
return builder.build().toByteArray();
Expand Down
Loading

0 comments on commit 54e5f86

Please sign in to comment.