Skip to content
Snippets Groups Projects
Commit ae485db3 authored by Zhibin Mai's avatar Zhibin Mai Committed by David Diederich
Browse files

Change the scope of the decimated properties

(cherry picked from commit 8fba2efd)
parent 0cfa9799
No related branches found
No related tags found
6 merge requests!604Merge Delta changes from M16 master to M18 master,!600Merge Delta changes from M16 master to M18 master,!599Merge Delta changes from M16 to M18 master,!598Merged from M16,!522M14 cherrypick to m16 master,!405Cherry-pick 'Geoshape decimation' into release/0.17
...@@ -172,11 +172,6 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat { ...@@ -172,11 +172,6 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat {
} }
if(hasVirtualDefaultLocation) { if(hasVirtualDefaultLocation) {
Map<String, Object> thumbnailProperty = new HashMap<>();
thumbnailProperty.put("path", VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_THUMBNAIL_PATH);
thumbnailProperty.put("kind", "core:dl:geoshape:1.0.0");
storageSchemaItems.add(thumbnailProperty);
Map<String, Object> isDecimatedProperty = new HashMap<>(); Map<String, Object> isDecimatedProperty = new HashMap<>();
isDecimatedProperty.put("path", VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH); isDecimatedProperty.put("path", VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH);
isDecimatedProperty.put("kind", "boolean"); isDecimatedProperty.put("kind", "boolean");
......
...@@ -195,6 +195,7 @@ public class StorageIndexerPayloadMapper { ...@@ -195,6 +195,7 @@ public class StorageIndexerPayloadMapper {
} }
VirtualProperties virtualProperties = (VirtualProperties) this.virtualPropertiesSchemaCache.get(storageSchema.getKind()); VirtualProperties virtualProperties = (VirtualProperties) this.virtualPropertiesSchemaCache.get(storageSchema.getKind());
String originalGeoShapeProperty = null;
for (Map.Entry<String, VirtualProperty> entry : virtualProperties.getProperties().entrySet()) { for (Map.Entry<String, VirtualProperty> entry : virtualProperties.getProperties().entrySet()) {
if (entry.getValue().getPriorities() == null || entry.getValue().getPriorities().size() == 0) { if (entry.getValue().getPriorities() == null || entry.getValue().getPriorities().size() == 0) {
continue; continue;
...@@ -211,23 +212,43 @@ public class StorageIndexerPayloadMapper { ...@@ -211,23 +212,43 @@ public class StorageIndexerPayloadMapper {
String virtualPropertyName = virtualPropertyPath + originalPropertyName.substring(originalPropertyPath.length()); String virtualPropertyName = virtualPropertyPath + originalPropertyName.substring(originalPropertyPath.length());
dataCollectorMap.put(virtualPropertyName, dataCollectorMap.get(originalPropertyName)); dataCollectorMap.put(virtualPropertyName, dataCollectorMap.get(originalPropertyName));
}); });
}
// Decimate the shape in VirtualProperties.DefaultLocation.Wgs84Coordinates when necessary if(virtualPropertyPath.equals(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION) &&
if(dataCollectorMap.containsKey(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH)) { dataCollectorMap.containsKey(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH)) {
try { originalGeoShapeProperty = originalPropertyPath + ".Wgs84Coordinates";
Map<String, Object> shapeObj = (Map<String, Object>)dataCollectorMap.get(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH);
DecimatedResult result = decimator.decimateShapeObj(shapeObj);
if(result.isDecimated()) {
dataCollectorMap.put(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH, result.getDecimatedShapeObj());
}
dataCollectorMap.put(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_THUMBNAIL_PATH, result.getThumbnailShapeObj());
dataCollectorMap.put(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH, result.isDecimated());
} }
catch(JsonProcessingException ex) { }
this.log.warning(String.format("record-id: %s | error decimating geoshape | error: %s", recordId, ex.getMessage()));
// No VirtualProperties.DefaultLocation.Wgs84Coordinates defined, use the default geo-shape property
String defaultGeoShapeProperty = "SpatialLocation.Wgs84Coordinates";
if(originalGeoShapeProperty == null && dataCollectorMap.containsKey(defaultGeoShapeProperty))
originalGeoShapeProperty = defaultGeoShapeProperty;
try {
decimateGeoShape(originalGeoShapeProperty, dataCollectorMap);
}
catch(JsonProcessingException ex) {
this.log.warning(String.format("record-id: %s | error decimating geoshape | error: %s", recordId, ex.getMessage()));
}
}
private void decimateGeoShape(String originalGeoShapeProperty, Map<String, Object> dataCollectorMap) throws JsonProcessingException {
if(originalGeoShapeProperty == null || !dataCollectorMap.containsKey(originalGeoShapeProperty))
return;
Map<String, Object> shapeObj = (Map<String, Object>)dataCollectorMap.get(originalGeoShapeProperty);
if(shapeObj == null)
return;
DecimatedResult result = decimator.decimateShapeObj(shapeObj);
if(result.isDecimated()) {
dataCollectorMap.put(originalGeoShapeProperty, result.getDecimatedShapeObj());
if(dataCollectorMap.containsKey(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH)) {
dataCollectorMap.put(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH, result.getDecimatedShapeObj());
} }
} }
if(dataCollectorMap.containsKey(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_WGS84_PATH)) {
dataCollectorMap.put(VirtualPropertyUtil.VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH, result.isDecimated());
}
} }
private Priority chooseOriginalProperty(String virtualPropertyPath, List<Priority> priorities, Map<String, Object> dataCollectorMap) { private Priority chooseOriginalProperty(String virtualPropertyPath, List<Priority> priorities, Map<String, Object> dataCollectorMap) {
......
...@@ -22,7 +22,6 @@ public class VirtualPropertyUtil { ...@@ -22,7 +22,6 @@ public class VirtualPropertyUtil {
public static final String VIRTUAL_DEFAULT_LOCATION = "VirtualProperties.DefaultLocation"; public static final String VIRTUAL_DEFAULT_LOCATION = "VirtualProperties.DefaultLocation";
public static final String FIELD_WGS84_COORDINATES = ".Wgs84Coordinates"; public static final String FIELD_WGS84_COORDINATES = ".Wgs84Coordinates";
public static final String VIRTUAL_DEFAULT_LOCATION_WGS84_PATH = VIRTUAL_DEFAULT_LOCATION + FIELD_WGS84_COORDINATES; public static final String VIRTUAL_DEFAULT_LOCATION_WGS84_PATH = VIRTUAL_DEFAULT_LOCATION + FIELD_WGS84_COORDINATES;
public static final String VIRTUAL_DEFAULT_LOCATION_THUMBNAIL_PATH = VIRTUAL_DEFAULT_LOCATION + ".Thumbnail";
public static final String VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH = VIRTUAL_DEFAULT_LOCATION + ".IsDecimated"; public static final String VIRTUAL_DEFAULT_LOCATION_IS_DECIMATED_PATH = VIRTUAL_DEFAULT_LOCATION + ".IsDecimated";
......
...@@ -7,6 +7,5 @@ import java.util.Map; ...@@ -7,6 +7,5 @@ import java.util.Map;
@Data @Data
public class DecimatedResult { public class DecimatedResult {
Map<String, Object> decimatedShapeObj; Map<String, Object> decimatedShapeObj;
Map<String, Object> thumbnailShapeObj;
boolean isDecimated = false; boolean isDecimated = false;
} }
...@@ -27,15 +27,12 @@ public class GeoShapeDecimator { ...@@ -27,15 +27,12 @@ public class GeoShapeDecimator {
if(type != null && type.equals("geometrycollection")) { if(type != null && type.equals("geometrycollection")) {
GeometryCollection geometryCollection = deserializerMapper.readValue(deserializerMapper.writeValueAsString(shapeObj), GeometryCollection.class); GeometryCollection geometryCollection = deserializerMapper.readValue(deserializerMapper.writeValueAsString(shapeObj), GeometryCollection.class);
boolean decimated = decimator.decimate(geometryCollection); boolean decimated = decimator.decimate(geometryCollection);
if (decimated) { result.setDecimated(decimated);
result.setDecimatedShapeObj( if(decimated) {
serializerMapper.readValue(serializerMapper.writeValueAsString(geometryCollection), new TypeReference<Map<String, Object>>() {})); // Must serialize the decimated shape before further decimating it as thumbnail
result.setDecimated(true); Map<String, Object> decimatedShapeObj = serializerMapper.readValue(serializerMapper.writeValueAsString(geometryCollection), new TypeReference<Map<String, Object>>() {});
result.setDecimatedShapeObj(decimatedShapeObj);
} }
// Must serialize the normal decimated shape before decimating it as thumbnail
decimator.decimateAsThumbnail(geometryCollection);
result.setThumbnailShapeObj(
serializerMapper.readValue(serializerMapper.writeValueAsString(geometryCollection), new TypeReference<Map<String, Object>>() {}));
} }
return result; return result;
......
...@@ -7,7 +7,6 @@ import java.util.List; ...@@ -7,7 +7,6 @@ import java.util.List;
public class GeometryDecimator { public class GeometryDecimator {
private static final double NormalShapeDecimationEpsilon = 10; // meters private static final double NormalShapeDecimationEpsilon = 10; // meters
private static final double ThumbnailShapeDecimationEpsilon = 1000; // meters
private static final double DegreesToMeters = 100000; // approximate using 100km per degree private static final double DegreesToMeters = 100000; // approximate using 100km per degree
private static final int MaxShapePointCountForLineDecimation = 300000; private static final int MaxShapePointCountForLineDecimation = 300000;
...@@ -15,10 +14,6 @@ public class GeometryDecimator { ...@@ -15,10 +14,6 @@ public class GeometryDecimator {
return decimate(geometryCollection, NormalShapeDecimationEpsilon); return decimate(geometryCollection, NormalShapeDecimationEpsilon);
} }
public boolean decimateAsThumbnail(GeometryCollection geometryCollection) {
return decimate(geometryCollection, ThumbnailShapeDecimationEpsilon);
}
private boolean decimate(GeometryCollection geometryCollection, double epsilon) { private boolean decimate(GeometryCollection geometryCollection, double epsilon) {
if(geometryCollection == null || geometryCollection.getGeometries() == null) if(geometryCollection == null || geometryCollection.getGeometries() == null)
return false; return false;
......
package org.opengroup.osdu.indexer.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import lombok.SneakyThrows;
import org.junit.Test;
import org.opengroup.osdu.indexer.model.geojson.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GeometryUtilTest {
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
GeometryDecimatorUtil util = new GeometryDecimatorUtil();
@Test
public void test1() {
String geoShapeJson = getGeoShapeFromFile("multi_line_string_projection_meter.json");
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> shapeObj = gson.fromJson(geoShapeJson, type);
try {
boolean decimated = util.decimateShapeObj(shapeObj);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
private void replaceCoordinates(Map<String, Object> featureCollection, Map<String, Object> geometryCollection) {
ArrayList features =(ArrayList)featureCollection.get("features");
for(Object feature: features) {
}
}
private int getTotalSize(FeatureCollection featureCollection) {
int size = 0;
for (Feature feature: featureCollection) {
GeoJsonObject geometry = feature.getGeometry();
if(geometry instanceof MultiLineString) {
MultiLineString multiLineString = ((MultiLineString) geometry);
for(List<Position> coordinates : multiLineString.getCoordinates()) {
size += coordinates.size();
}
}
else if(geometry instanceof LineString) {
LineString lineString = ((LineString)geometry);
size += lineString.getCoordinates().size();
}
}
return size;
}
@SneakyThrows
private String getGeoShapeFromFile(String file) {
InputStream inStream = this.getClass().getResourceAsStream("/geometry-decimation/" + file);
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
StringBuilder stringBuilder = new StringBuilder();
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null)
{
stringBuilder.append(sCurrentLine).append("\n");
}
return stringBuilder.toString();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment