Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata extents API / Make configurable to display the metadata bboxes using geodesic extents for local projections. #7560

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2021 Food and Agriculture Organization of the
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
Expand Down Expand Up @@ -128,6 +128,7 @@ public class Settings {
public static final String REGION_GETMAP_MAPPROJ = "region/getmap/mapproj";
public static final String REGION_GETMAP_WIDTH = "region/getmap/width";
public static final String REGION_GETMAP_SUMMARY_WIDTH = "region/getmap/summaryWidth";
public static final String REGION_GETMAP_GEODESIC_EXTENTS = "region/getmap/useGeodesicExtents";
public static final String METADATA_WORKFLOW_ENABLE = "metadata/workflow/enable";
public static final String METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP = "metadata/workflow/draftWhenInGroup";
public static final String METADATA_WORKFLOW_ALLOW_SUBMIT_APPROVE_INVALID_MD = "metadata/workflow/allowSubmitApproveInvalidMd";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2022 Food and Agriculture Organization of the
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
Expand All @@ -24,7 +24,6 @@
package org.fao.geonet.api.records.extent;

import jeeves.server.context.ServiceContext;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.api.regions.GeomFormat;
import org.fao.geonet.exceptions.BadParameterEx;
Expand All @@ -33,31 +32,22 @@
import org.fao.geonet.kernel.region.RegionsDAO;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.lib.Lib;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.locationtech.jts.awt.ShapeWriter;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.geotools.api.metadata.extent.Extent;
import org.geotools.api.metadata.extent.GeographicBoundingBox;
import org.geotools.api.metadata.extent.GeographicExtent;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.referencing.operation.MathTransform;
import org.springframework.context.ApplicationContext;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.Map;
import java.util.SortedSet;
Expand Down Expand Up @@ -89,30 +79,28 @@ public static AffineTransform worldToScreenTransform(Envelope mapExtent, Dimensi
* intersection of the geometry with the coordinate system domain of validity.
*/
public static Geometry computeGeomInDomainOfValidity(Geometry geom, CoordinateReferenceSystem mapCRS) {
final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
final Extent domainOfValidity = mapCRS.getDomainOfValidity();
Geometry adjustedGeom = geom;
if (domainOfValidity != null) {
for (final GeographicExtent extent :
domainOfValidity.getGeographicElements()) {
if (Boolean.FALSE.equals(extent.getInclusion())) {
if ((extent == null) || (Boolean.FALSE.equals(extent.getInclusion()))) {
continue;
}

if (extent instanceof GeographicBoundingBox) {
if (extent != null) {
GeographicBoundingBox box = (GeographicBoundingBox) extent;
GeographicBoundingBox box = (GeographicBoundingBox) extent;

Envelope env = new Envelope(
box.getWestBoundLongitude(),
box.getEastBoundLongitude(),
box.getSouthBoundLatitude(),
box.getNorthBoundLatitude());
if (env.contains(geom.getEnvelopeInternal())) {
return geom;
} else {
Geometry extentPolygon = JTS.toGeometry(env);
adjustedGeom = geom.intersection(extentPolygon);
}
Envelope env = new Envelope(
box.getWestBoundLongitude(),
box.getEastBoundLongitude(),
box.getSouthBoundLatitude(),
box.getNorthBoundLatitude());
if (env.contains(geom.getEnvelopeInternal())) {
return geom;
} else {
Geometry extentPolygon = JTS.toGeometry(env);
adjustedGeom = geom.intersection(extentPolygon);
}
}
}
Expand All @@ -123,11 +111,14 @@ public static Geometry computeGeomInDomainOfValidity(Geometry geom, CoordinateRe
}

public BufferedImage render(String id, String srs, Integer width, Integer height,
String background, String geomParam, String geomType, String geomSrs, String fillColor, String strokeColor) throws Exception {
String background, String geomParam, String geomType,
String geomSrs, String fillColor, String strokeColor) throws Exception {
ApplicationContext appContext = context.getApplicationContext();
Map<String, String> regionGetMapBackgroundLayers = appContext.getBean("regionGetMapBackgroundLayers", Map.class);
SortedSet<ExpandFactor> regionGetMapExpandFactors = appContext.getBean("regionGetMapExpandFactors", SortedSet.class);
SettingManager settingManager = appContext.getBean(SettingManager.class);
boolean isGlobalSrs = srs.equals("EPSG:4326") || srs.equals("EPSG:3857");
boolean useGeodesicExtents = settingManager.getValueAsBool(Settings.REGION_GETMAP_GEODESIC_EXTENTS, false);

Geometry geom = null;
if (id != null) {
Expand Down Expand Up @@ -192,7 +183,6 @@ public BufferedImage render(String id, String srs, Integer width, Integer height
;

BufferedImage baseMapImage = baseMapRenderer.render();
// ImageIO.write(baseMapImage, "png", new File("delme.png"));

image = baseMapImage;
} else {
Expand All @@ -209,8 +199,9 @@ public BufferedImage render(String id, String srs, Integer width, Integer height
Color geomStrokeColor = getColor(strokeColor, new Color(0, 0, 0, 255));
AffineTransform worldToScreenTransform = worldToScreenTransform(bboxOfImage, imageDimensions);
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry geomExtent = (!isGlobalSrs && !useGeodesicExtents ? geom.getGeometryN(i).getEnvelope() : geom.getGeometryN(i));
// draw each included geometry separately to ensure they are filled correctly
Shape shape = worldToScreenTransform.createTransformedShape(shapeWriter.toShape(geom.getGeometryN(i)));
Shape shape = worldToScreenTransform.createTransformedShape(shapeWriter.toShape(geomExtent));
graphics.setColor(geomFillColor);
graphics.fill(shape);

Expand Down
2 changes: 2 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@
"region/getmap/background": "Background map, URL or Named Layer ID",
"region/getmap/mapproj": "Map projection",
"region/getmap/summaryWidth": "Summary width",
"region/getmap/useGeodesicExtents": "Display geodesic extents",
"region/getmap/useGeodesicExtents-help": "By default, the displayed metadata extents are planar (i.e. rectangular). If you enable this option, the metadata extents will become geodesic. If the map uses a projected coordinate system, this may lead to non-rectangular extents (e.g. trapezoid).",
"region/getmap/width": "Width",
"metadata/editor": "Metadata editor configuration",
"metadata/editor/schemaConfig": "Standard configuration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region/getmap/width', '500', 0, 9590, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region/getmap/summaryWidth', '500', 0, 9590, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region/getmap/mapproj', 'EPSG:3857', 0, 9590, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region/getmap/useGeodesicExtents', 'false', 2, 9591, 'n');


INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/url/sitemapLinkUrl', NULL, 0, 9165, 'y');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
UPDATE Settings SET value='4.4.2' WHERE name='system/platform/version';
UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion';

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('region/getmap/useGeodesicExtents', 'false', 2, 9591, 'n');

ALTER TABLE public.spg_page ADD icon varchar NULL;
Loading