added spatial boundingbox support using a 4 sides polygon wkt format

This commit is contained in:
Enrico Ottonello 2021-06-17 17:59:51 +02:00
parent 03da34a897
commit 8ed4b8b08d
9 changed files with 75 additions and 150 deletions

View File

@ -6,19 +6,28 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.lucene.spatial3d.geom.GeoPoint;
import org.apache.lucene.spatial3d.geom.GeoPolygon;
import org.apache.lucene.spatial3d.geom.GeoPolygonFactory;
import org.apache.lucene.spatial3d.geom.PlanetModel;
import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.EnvelopeBuilder;
import org.elasticsearch.common.geo.builders.PolygonBuilder;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.geometry.Polygon;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -74,10 +83,35 @@ public class BulkUpload {
.forEach(s -> { .forEach(s -> {
double lat = Double.parseDouble(s.getLat()); double lat = Double.parseDouble(s.getLat());
double lon = Double.parseDouble(s.getLon()); double lon = Double.parseDouble(s.getLon());
GeoPoint geopoint = new GeoPoint(lat, lon); org.elasticsearch.common.geo.GeoPoint geopoint = new org.elasticsearch.common.geo.GeoPoint(lat, lon);
s.setGeopoint(geopoint); s.setGeopoint(geopoint);
}); });
// TODO update following check according to new model definition ace.getSpatial()
.stream()
.filter(s -> Objects.nonNull(s.getBoundingBoxMaxLat())
&& Objects.nonNull(s.getBoundingBoxMaxLon())
&& Objects.nonNull(s.getBoundingBoxMinLat())
&& Objects.nonNull(s.getBoundingBoxMinLon()))
.forEach(s -> {
double maxlat = Double.parseDouble(s.getBoundingBoxMaxLat());
double minlat = Double.parseDouble(s.getBoundingBoxMinLat());
double minlon = Double.parseDouble(s.getBoundingBoxMinLon());
double maxlon = Double.parseDouble(s.getBoundingBoxMaxLon());
CoordinatesBuilder coordinatesBuilder = new CoordinatesBuilder();
coordinatesBuilder.coordinate(minlon, maxlat);
coordinatesBuilder.coordinate(minlon, minlat);
coordinatesBuilder.coordinate(maxlon, minlat);
coordinatesBuilder.coordinate(maxlon, maxlat);
coordinatesBuilder.coordinate(minlon, maxlat);
PolygonBuilder polygonBuilder = new PolygonBuilder(coordinatesBuilder);
String wkt = polygonBuilder.toWKT();
s.setBoundingbox(wkt);
// Coordinate topLeft = new Coordinate(minlon, maxlat);
// Coordinate bottomRight = new Coordinate(maxlon, minlat);
// EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(topLeft, bottomRight);
// String wkt = envelopeBuilder.toWKT();
// s.setBoundingbox(wkt);
});
if (ace.getSpatial().size()==2) { if (ace.getSpatial().size()==2) {
Spatial uniqueSpatial = new Spatial(); Spatial uniqueSpatial = new Spatial();
boolean uniquePlaceNameFound = ace.getSpatial().stream().filter(s -> s.getPlaceName()!=null).count()==1; boolean uniquePlaceNameFound = ace.getSpatial().stream().filter(s -> s.getPlaceName()!=null).count()==1;
@ -118,13 +152,13 @@ public class BulkUpload {
} }
} }
if (ace.getTemporal()!=null) { // if (ace.getTemporal()!=null) {
ace.getTemporal().stream() // ace.getTemporal().stream()
.filter(t->t.getMatchingPeriodOName()!=null) // .filter(t->t.getMatchingPeriodOName()!=null)
.forEach(t->{ // .forEach(t->{
t.setPeriodName(t.getMatchingPeriodOName()); // t.setPeriodName(t.getMatchingPeriodOName());
}); // });
} // }
if (!isCollection) { if (!isCollection) {
String uniqueIsPartOf = ace.getUniqueIsPartOf(); String uniqueIsPartOf = ace.getUniqueIsPartOf();
@ -139,15 +173,7 @@ public class BulkUpload {
String[] splits = ace.getIdentifier().split("/"); String[] splits = ace.getIdentifier().split("/");
// if (ace.getAatSubjects() != null && ace.getDerivedSubject() != null) { log.debug("JSON >>>> "+ace.toJson());
// String aatSource = ace.getAatSubjects().get(0).getId();
// ace.getDerivedSubject().forEach(d -> {
// d.setSource(aatSource);
// });
// String [] aatSourceSplit = aatSource.split("/");
// String aatSubjectId = aatSourceSplit[aatSourceSplit.length-1];
// ace.getAatSubjects().forEach(s -> s.setId(aatSubjectId));
// }
String idES = splits[splits.length-1]; String idES = splits[splits.length-1];
request.add(new IndexRequest(elasticSearchIndexName).id(idES) request.add(new IndexRequest(elasticSearchIndexName).id(idES)

View File

@ -1,46 +0,0 @@
package eu.dnetlib.ariadneplus.elasticsearch.model;
import com.google.gson.Gson;
public class AriadneGeoPoint {
private float lat;
private float lon;
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLon() {
return lon;
}
public void setLon(float lon) {
this.lon = lon;
}
public AriadneGeoPoint() {
}
public static AriadneGeoPoint fromJson (String json){
return new Gson().fromJson(json, AriadneGeoPoint.class);
}
// public static AriadneGeoPoint fromRDFJson(JsonElement json){
// AriadneGeoPoint agp = new AriadneGeoPoint();
// for (Map.Entry<String, JsonElement> stringJsonElementEntry : json.getAsJsonObject().entrySet()) {
// switch (stringJsonElementEntry.getKey()){
// case "https://www.ariadne-infrastructure.eu/property/lat":
// agp.setLat(stringJsonElementEntry.getValue().getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString());
// break;
// case "https://www.ariadne-infrastructure.eu/property/lon":
// agp.setLon(stringJsonElementEntry.getValue().getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString());
// break;
// }
// }
// return agp;
// }
}

View File

@ -1,46 +0,0 @@
package eu.dnetlib.ariadneplus.elasticsearch.model;
import com.google.gson.Gson;
public class AriadneGeoShape {
private float lat;
private float lon;
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLon() {
return lon;
}
public void setLon(float lon) {
this.lon = lon;
}
public AriadneGeoShape() {
}
public static AriadneGeoShape fromJson (String json){
return new Gson().fromJson(json, AriadneGeoShape.class);
}
// public static AriadneGeoPoint fromRDFJson(JsonElement json){
// AriadneGeoPoint agp = new AriadneGeoPoint();
// for (Map.Entry<String, JsonElement> stringJsonElementEntry : json.getAsJsonObject().entrySet()) {
// switch (stringJsonElementEntry.getKey()){
// case "https://www.ariadne-infrastructure.eu/property/lat":
// agp.setLat(stringJsonElementEntry.getValue().getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString());
// break;
// case "https://www.ariadne-infrastructure.eu/property/lon":
// agp.setLon(stringJsonElementEntry.getValue().getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString());
// break;
// }
// }
// return agp;
// }
}

View File

@ -31,7 +31,7 @@ public class AriadnePlusEntry {
private List<Spatial> spatial; private List<Spatial> spatial;
private List<Temporal> temporal; private List<Temporal> temporal;
private String title; private String title;
private NativePeriod nativePeriod; private List<NativePeriod> nativePeriod;
private String wasCreated; private String wasCreated;
private DigitalImage digitalImage; private DigitalImage digitalImage;
@ -268,14 +268,6 @@ public class AriadnePlusEntry {
this.ariadneSubject = ariadneSubject; this.ariadneSubject = ariadneSubject;
} }
public NativePeriod getNativePeriod() {
return nativePeriod;
}
public void setNativePeriod(NativePeriod nativePeriod) {
this.nativePeriod = nativePeriod;
}
public DigitalImage getDigitalImage() { public DigitalImage getDigitalImage() {
return digitalImage; return digitalImage;
} }
@ -284,6 +276,14 @@ public class AriadnePlusEntry {
this.digitalImage = digitalImage; this.digitalImage = digitalImage;
} }
public List<NativePeriod> getNativePeriod() {
return nativePeriod;
}
public void setNativePeriod(List<NativePeriod> nativePeriod) {
this.nativePeriod = nativePeriod;
}
public String toJson(){ public String toJson(){
return new Gson().toJson(this); return new Gson().toJson(this);
} }

View File

@ -9,8 +9,8 @@ public class Spatial {
private String placeName; private String placeName;
private String address; private String address;
private GeoPoint geopoint; private GeoPoint geopoint;
private GeoShape boundingbox; private String boundingbox;
private GeoShape polygon; private String polygon;
private String spatialPrecision; private String spatialPrecision;
private transient String coordinatePrecision; private transient String coordinatePrecision;
@ -69,22 +69,6 @@ public class Spatial {
this.placeName = placeName; this.placeName = placeName;
} }
public GeoShape getBoundingbox() {
return boundingbox;
}
public void setBoundingbox(GeoShape boundingbox) {
this.boundingbox = boundingbox;
}
public GeoShape getPolygon() {
return polygon;
}
public void setPolygon(GeoShape polygon) {
this.polygon = polygon;
}
public String getSpatialPrecision() { public String getSpatialPrecision() {
return spatialPrecision; return spatialPrecision;
} }
@ -117,10 +101,26 @@ public class Spatial {
this.lon = lon; this.lon = lon;
} }
public String getBoundingbox() {
return boundingbox;
}
public void setBoundingbox(String boundingbox) {
this.boundingbox = boundingbox;
}
public GeoPoint getGeopoint() { public GeoPoint getGeopoint() {
return geopoint; return geopoint;
} }
public String getPolygon() {
return polygon;
}
public void setPolygon(String polygon) {
this.polygon = polygon;
}
public void setGeopoint(GeoPoint geopoint) { public void setGeopoint(GeoPoint geopoint) {
this.geopoint = geopoint; this.geopoint = geopoint;
} }

View File

@ -10,7 +10,6 @@ public class Temporal {
private String periodName; private String periodName;
private String until; private String until;
private String uri; private String uri;
private transient String matchingPeriodOName;
public String getFrom() { public String getFrom() {
return from; return from;
@ -50,12 +49,4 @@ public class Temporal {
public static Temporal fromJson(String json){ public static Temporal fromJson(String json){
return new Gson().fromJson(json, Temporal.class); return new Gson().fromJson(json, Temporal.class);
} }
public String getMatchingPeriodOName() {
return matchingPeriodOName;
}
public void setMatchingPeriodOName(String matchingPeriodOName) {
this.matchingPeriodOName = matchingPeriodOName;
}
} }

View File

@ -47,7 +47,7 @@ CONSTRUCT {
?temporal aoprop:from ?temporalFrom . ?temporal aoprop:from ?temporalFrom .
?temporal aoprop:until ?temporalUntil . ?temporal aoprop:until ?temporalUntil .
?temporal aoprop:uri ?temporal . ?temporal aoprop:uri ?temporal .
%record aoprop:temporal ?temporalNative . %record aoprop:temporalNative ?temporalNative .
?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName . ?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName .
?temporalNative aoprop:from ?temporalNativeFrom . ?temporalNative aoprop:from ?temporalNativeFrom .
?temporalNative aoprop:until ?temporalNativeUntil . ?temporalNative aoprop:until ?temporalNativeUntil .

View File

@ -47,7 +47,7 @@ CONSTRUCT {
?temporal aoprop:from ?temporalFrom . ?temporal aoprop:from ?temporalFrom .
?temporal aoprop:until ?temporalUntil . ?temporal aoprop:until ?temporalUntil .
?temporal aoprop:uri ?temporal . ?temporal aoprop:uri ?temporal .
%record aoprop:temporal ?temporalNative . %record aoprop:temporalNative ?temporalNative .
?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName . ?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName .
?temporalNative aoprop:from ?temporalNativeFrom . ?temporalNative aoprop:from ?temporalNativeFrom .
?temporalNative aoprop:until ?temporalNativeUntil . ?temporalNative aoprop:until ?temporalNativeUntil .

View File

@ -131,7 +131,7 @@ public class GraphDbReaderAndESIndexTest {
} }
@Test @Test
@Ignore // @Ignore
public void uploadADSArchivesBoundingBoxTest() throws Exception { public void uploadADSArchivesBoundingBoxTest() throws Exception {
boolean isRecord = true; boolean isRecord = true;
String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/90D1C95D-E249-3E74-92D9-B58FDF690CC7"; String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/90D1C95D-E249-3E74-92D9-B58FDF690CC7";