Skip to content

Commit

Permalink
mvt layer性能优化
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmiao committed Mar 15, 2023
1 parent 25da7b6 commit 2c2ecf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo

}

/**
* 新建一个图层,按simplifyDistance的值简化geometry
*
* @param layerName 图层名 本方法没有对图层名进行唯一校验,故若图层已存在,则原图层会被覆盖
* @param simplifyDistance 对geometry进行简化的长度,单位是瓦片像素,取值范围[0,extent+clipBuffer],为0时表示不做简化
* @return MvtLayer
*/
public MvtLayer createLayer(String layerName, int simplifyDistance) {
MvtLayer layer = new MvtLayer(this, simplifyDistance);
layers.put(layerName, layer);
return layer;
}
/**
* 新建一个图层,不对geometry进行简化
*
* @param layerName 图层名 本方法没有对图层名进行唯一校验,故若图层已存在,则原图层会被覆盖
* @return MvtLayer
*/
public MvtLayer createLayer(String layerName) {
return createLayer(layerName, 0);
}

/**
* 新建或获取一个图层,按simplifyDistance的值简化geometry
*
Expand All @@ -88,9 +110,7 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo
if (layer != null) {
return layer;
}
layer = new MvtLayer(this, simplifyDistance);
layers.put(layerName, layer);
return layer;
return createLayer(layerName, simplifyDistance);
}

/**
Expand All @@ -104,9 +124,7 @@ public MvtBuilder(byte z, int x, int y, int extent, int clipBuffer, @NotNull Geo
if (layer != null) {
return layer;
}
layer = new MvtLayer(this, 0);
layers.put(layerName, layer);
return layer;
return createLayer(layerName, 0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.locationtech.jts.geom.GeometryCollection;
import org.locationtech.jts.geom.TopologyException;
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
import org.wowtools.giscat.vector.util.analyse.Bbox;
import org.wowtools.giscat.vector.pojo.Feature;
import org.wowtools.giscat.vector.util.analyse.Bbox;

import java.util.*;

Expand All @@ -38,7 +38,7 @@
*/
public final class MvtLayer {

protected final List<MvtFeature> features = new ArrayList<>();
protected final List<MvtFeature> features = new LinkedList<>();

private final Map<String, Integer> keys = new LinkedHashMap<>();
private final Map<Object, Integer> values = new LinkedHashMap<>();
Expand Down Expand Up @@ -145,16 +145,16 @@ private ArrayList<Integer> tags(@Nullable Map<String, ?> attributes) {
return keys.computeIfAbsent(key, k -> keys.size());
}

protected @NotNull List<String> keys() {
return new ArrayList<>(keys.keySet());
protected @NotNull Set<String> keys() {
return keys.keySet();
}

private @NotNull Integer value(Object value) {
return values.computeIfAbsent(value, k -> values.size());
}

protected List<Object> values() {
return List.copyOf(values.keySet());
protected Set<Object> values() {
return values.keySet();
}


Expand Down

0 comments on commit 2c2ecf9

Please sign in to comment.