removed PointsPath and passed to Geometry JSON string

This commit is contained in:
Francesco Mangiacrapa 2021-09-06 16:39:12 +02:00
parent ad71d45158
commit 0e082c0c37
6 changed files with 188 additions and 165 deletions

View File

@ -48,14 +48,20 @@ public class GeoportalDataViewerConstants {
public static enum MAP_PROJECTION { public static enum MAP_PROJECTION {
EPSG_4326("EPSG:4326"), EPSG_3857("EPSG:3857"); EPSG_4326("4326", "EPSG:4326"), EPSG_3857("3857", "EPSG:3857");
String id;
String name; String name;
MAP_PROJECTION(String name) { MAP_PROJECTION(String id, String name) {
this.id = id;
this.name = name; this.name = name;
} }
public String getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -88,7 +94,6 @@ public class GeoportalDataViewerConstants {
console.log("js obj: " + JSON.stringify(object, null, 4)); console.log("js obj: " + JSON.stringify(object, null, 4));
}-*/; }-*/;
/** /**
* Prints the. * Prints the.
* *

View File

@ -21,6 +21,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEventH
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM;
import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
@ -29,7 +31,6 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.PointsPath;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis;
@ -41,6 +42,8 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event;
@ -52,6 +55,10 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
import ol.Coordinate; import ol.Coordinate;
import ol.Extent;
import ol.OLFactory;
import ol.format.GeoJson;
import ol.geom.Geometry;
/** /**
* The Class LayerManager. * The Class LayerManager.
@ -350,17 +357,69 @@ public class LayerManager {
} }
Coordinate centerTo = null; Coordinate centerTo = null;
GWT.log("geometry is: " + feature.getGeometry());
if (feature.getGeometry() != null) { if (feature.getGeometry() != null) {
GWT.log("trasforming geometry: " + feature.getGeometry().getToJSONObject());
PointsPath path = feature.getGeometry().getPath(); Geometry geom = new GeoJson()
GWT.log("Points Path: " + path); .readGeometry(feature.getGeometry().getToJSONObject(), null);
if (path != null && path.getCoordinates() != null
&& path.getCoordinates().length > 0) { //POINT
org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.Coordinate center = path if (geom.getType().equalsIgnoreCase("Point")) {
.getCoordinates()[0]; GWT.log("geometry: is a point");
centerTo = new Coordinate(center.getX(), center.getY()); String coordinateJSON = feature.getGeometry().getCoordinatesJSON();
JSONArray centerJSON = (JSONArray) JSONParser
.parseStrict(coordinateJSON);
// Coordinate center = OLFactory.createCoordinate(
// new Double(centerJSON.get(0).toString()),
// new Double(centerJSON.get(1).toString()));
Coordinate center = new Coordinate(new Double(centerJSON.get(0).toString()),
new Double(centerJSON.get(1).toString()));
if (feature.getCrsName() != null && feature.getCrsName().endsWith(MAP_PROJECTION.EPSG_4326.getId())) {
center = MapUtils.transformCoordiante(center,
MAP_PROJECTION.EPSG_4326.getName(),
MAP_PROJECTION.EPSG_3857.getName());
} }
centerTo = center;
} else {
Extent geomExtent = geom.getExtent();
Coordinate lower = OLFactory.createCoordinate(
geomExtent.getLowerLeftX(), geomExtent.getLowerLeftY());
Coordinate upper = OLFactory.createCoordinate(
geomExtent.getUpperRightX(), geomExtent.getUpperRightY());
Coordinate lowerCoord = lower;
Coordinate upperCoord = upper;
if (feature.getCrsName() != null && feature.getCrsName()
.endsWith(MAP_PROJECTION.EPSG_4326.getId())) {
lowerCoord = MapUtils.transformCoordiante(lower,
MAP_PROJECTION.EPSG_4326.getName(),
MAP_PROJECTION.EPSG_3857.getName());
upperCoord = MapUtils.transformCoordiante(upper,
MAP_PROJECTION.EPSG_4326.getName(),
MAP_PROJECTION.EPSG_3857.getName());
}
ExtentWrapped ew = new ExtentWrapped(lowerCoord.getX(),
lowerCoord.getY(), upperCoord.getX(), upperCoord.getY());
centerTo = new Coordinate(ew.getCenter().getX(), ew.getCenter().getY());
}
GWT.log("center is: "+centerTo);
// PointsPath path = feature.getGeometry().getPath();
// GWT.log("Points Path: " + path);
// if (path != null && path.getCoordinates() != null
// && path.getCoordinates().length > 0) {
// org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.Coordinate center = path
// .getCoordinates()[0];
// centerTo = new Coordinate(center.getX(), center.getY());
// }
} }
// fallback // fallback

View File

@ -19,17 +19,14 @@ import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
import org.gcube.application.geoportalcommon.util.URLParserUtil; import org.gcube.application.geoportalcommon.util.URLParserUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.Coordinate;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureGeometry; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureGeometry;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.PointsPath;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class FeatureParser. * The Class FeatureParser.
* *
@ -50,7 +47,8 @@ public class FeatureParser {
* @param maxWFSFeature the max WFS feature * @param maxWFSFeature the max WFS feature
* @return the WFS features * @return the WFS features
*/ */
public static List<FeatureRow> getWFSFeatures(LayerItem layerItem, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature) { public static List<FeatureRow> getWFSFeatures(LayerItem layerItem, String mapSrsName, BoundsMap selectBBOX,
int maxWFSFeature) {
if (maxWFSFeature < 0) { if (maxWFSFeature < 0) {
maxWFSFeature = GeoportalDataViewerConstants.MAX_WFS_FEATURES; maxWFSFeature = GeoportalDataViewerConstants.MAX_WFS_FEATURES;
@ -58,9 +56,6 @@ public class FeatureParser {
return getWFSFeatureProperties(layerItem, mapSrsName, selectBBOX, maxWFSFeature); return getWFSFeatureProperties(layerItem, mapSrsName, selectBBOX, maxWFSFeature);
} }
/** /**
* Gets the WFS feature properties. * Gets the WFS feature properties.
* *
@ -71,20 +66,24 @@ public class FeatureParser {
* @return the WFS feature properties * @return the WFS feature properties
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static List<FeatureRow> getWFSFeatureProperties(LayerItem layerItem, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature) { private static List<FeatureRow> getWFSFeatureProperties(LayerItem layerItem, String mapSrsName,
BoundsMap selectBBOX, int maxWFSFeature) {
LOG.info("getWFSFeatureProperties for layerItem: "+layerItem.getName() +" in the "+selectBBOX +" and maxWFSFeature: "+maxWFSFeature); LOG.info("getWFSFeatureProperties for layerItem: " + layerItem.getName() + " in the " + selectBBOX
+ " and maxWFSFeature: " + maxWFSFeature);
InputStream is = null; InputStream is = null;
List<FeatureRow> listFeaturesRow = new ArrayList<FeatureRow>(); List<FeatureRow> listFeaturesRow = new ArrayList<FeatureRow>();
try { try {
String url = GisMakers.buildWFSFeatureQuery(layerItem, mapSrsName, selectBBOX, maxWFSFeature, GisMakers.JSON); String url = GisMakers.buildWFSFeatureQuery(layerItem, mapSrsName, selectBBOX, maxWFSFeature,
GisMakers.JSON);
String cqlFilterValue = URLParserUtil.extractValueOfParameterFromURL(GisMakers.CQL_FILTER_PARAMETER, url); String cqlFilterValue = URLParserUtil.extractValueOfParameterFromURL(GisMakers.CQL_FILTER_PARAMETER, url);
LOG.info("Found CQL filter value into query string: " + cqlFilterValue); LOG.info("Found CQL filter value into query string: " + cqlFilterValue);
if (cqlFilterValue != null) { if (cqlFilterValue != null) {
String notEncodedCQLFilter = String.format("%s=%s", GisMakers.CQL_FILTER_PARAMETER, cqlFilterValue); String notEncodedCQLFilter = String.format("%s=%s", GisMakers.CQL_FILTER_PARAMETER, cqlFilterValue);
// log.info("Found CQL filter: "+notEncodedCQLFilter); // log.info("Found CQL filter: "+notEncodedCQLFilter);
String toEncodeCQLFilter = String.format("%s=%s",GisMakers.CQL_FILTER_PARAMETER,URLEncoder.encode(cqlFilterValue,"UTF-8")); String toEncodeCQLFilter = String.format("%s=%s", GisMakers.CQL_FILTER_PARAMETER,
URLEncoder.encode(cqlFilterValue, "UTF-8"));
LOG.debug("Encoded CQL filter: " + toEncodeCQLFilter); LOG.debug("Encoded CQL filter: " + toEncodeCQLFilter);
url = url.replace(notEncodedCQLFilter, toEncodeCQLFilter); url = url.replace(notEncodedCQLFilter, toEncodeCQLFilter);
} }
@ -127,29 +126,34 @@ public class FeatureParser {
try { try {
JSONObject geometry = theFeature.getJSONObject("geometry"); JSONObject geometry = theFeature.getJSONObject("geometry");
String typeValue = geometry.getString("type"); String typeValue = geometry.getString("type");
JSONArray coordinates = geometry.getJSONArray("coordinates"); // JSONArray coordinates = geometry.getJSONArray("coordinates");
// String toCoordinates = coordinates.toString(); // String toCoordinates = coordinates.toString();
String x1 = coordinates.get(0).toString(); // String x1 = coordinates.get(0).toString();
String y1 = coordinates.get(1).toString(); // String y1 = coordinates.get(1).toString();
LOG.debug("Coordinate x1: "+x1); // LOG.debug("Coordinate x1: "+x1);
LOG.debug("Coordinate y1: "+y1); // LOG.debug("Coordinate y1: "+y1);
Double coordX = null; // Double coordX = null;
Double coordY = null; // Double coordY = null;
FeatureGeometry fg = new FeatureGeometry(); FeatureGeometry fg = new FeatureGeometry();
fg.setType(typeValue); fg.setType(typeValue);
// TODO ONLY POINT GEOMETRY // TODO ONLY POINT GEOMETRY
try { try {
coordX = Double.parseDouble(x1); JSONArray coordinates = geometry.getJSONArray("coordinates");
coordY = Double.parseDouble(y1); String coordinateJSONString = coordinates.toString();
Coordinate coord = new Coordinate(coordX, coordY); LOG.debug("coordinates are: " + coordinateJSONString);
fg.setPath(new PointsPath(new Coordinate[] {coord})); fg.setCoordinatesJSON(coordinates.toString());
// coordX = Double.parseDouble(x1);
// coordY = Double.parseDouble(y1);
// Coordinate coord = new Coordinate(coordX, coordY);
// fg.setPath(new PointsPath(new Coordinate[] {coord}));
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Not able to parse the 'coordinates' field: ", e); LOG.warn("Not able to parse the 'coordinates' field: ", e);
} }
row.setGeometry(fg); row.setGeometry(fg);
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Unable to pase geometry at index: "+i); LOG.debug("Unable to parse geometry at index: " + i);
} }
// // iterate properties // // iterate properties

View File

@ -3,44 +3,60 @@ package org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs;
import java.io.Serializable; import java.io.Serializable;
/** /**
* The Class FeatureGeoemtry. * The Class FeatureGeometry.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Oct 29, 2020 * Sep 6, 2021
*/ */
public class FeatureGeometry implements WFSGeometry, Serializable { public class FeatureGeometry implements WFSGeometry, Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 6251162740446739453L; private static final long serialVersionUID = 8134176011135233810L;
private String type; private String type;
private PointsPath path; private String coordinatesJSON;
private String toJSON;
/**
* Instantiates a new feature geometry.
*/
public FeatureGeometry() { public FeatureGeometry() {
} }
public FeatureGeometry(String type, PointsPath path) { /**
* Instantiates a new feature geometry.
*
* @param type the type
* @param coordinatesJSON the coordinates JSON
*/
public FeatureGeometry(String type, String coordinatesJSON) {
super(); super();
this.type = type; this.type = type;
this.path = path; this.coordinatesJSON = coordinatesJSON;
} }
public String getType() { public String getType() {
return type; return type;
} }
public String getCoordinatesJSON() {
return coordinatesJSON;
}
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public PointsPath getPath() { public void setCoordinatesJSON(String coordinatesJSON) {
return path; this.coordinatesJSON = coordinatesJSON;
} }
public void setPath(PointsPath path) { public String getToJSONObject() {
this.path = path; if(toJSON==null)
toJSON = "{\"type\":\""+type+"\",\"coordinates\":"+coordinatesJSON+"}";
return toJSON;
} }
@Override @Override
@ -48,8 +64,8 @@ public class FeatureGeometry implements WFSGeometry, Serializable {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("FeatureGeometry [type="); builder.append("FeatureGeometry [type=");
builder.append(type); builder.append(type);
builder.append(", path="); builder.append(", coordinatesJSON=");
builder.append(path); builder.append(coordinatesJSON);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }

View File

@ -1,60 +0,0 @@
package org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs;
import java.io.Serializable;
import java.util.Arrays;
/**
* The Class PointsPath.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 16, 2020
*/
public class PointsPath implements Serializable{
/**
*
*/
private static final long serialVersionUID = -3295493507974317970L;
private Coordinate[] coordinates;
/**
* Instantiates a new points path.
*/
public PointsPath() {
}
/**
* Instantiates a new points path.
*
* @param coordinates the coordinates
*/
public PointsPath(Coordinate[] coordinates) {
super();
this.coordinates = coordinates;
}
public Coordinate[] getCoordinates() {
return coordinates;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PointsPath [coordinates=");
builder.append(Arrays.toString(coordinates));
builder.append("]");
return builder.toString();
}
}

View File

@ -4,9 +4,9 @@ package org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs;
/** /**
* The Interface WFSGeometry. * The Interface WFSGeometry.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Nov 16, 2020 * Sep 6, 2021
*/ */
public interface WFSGeometry { public interface WFSGeometry {
@ -17,12 +17,11 @@ public interface WFSGeometry {
*/ */
String getType(); String getType();
/** /**
* Gets the path. * Gets the coordinates JSON.
* *
* @return the path * @return the coordinates JSON
*/ */
PointsPath getPath(); String getCoordinatesJSON();
} }