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

[Issue842] Enable setting of title, abstract and keywords on Grid and GridSet #844

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
77 changes: 76 additions & 1 deletion geowebcache/core/src/main/java/org/geowebcache/grid/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,34 @@
package org.geowebcache.grid;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/** @author groldan */
public class Grid implements Serializable, Cloneable {

private static final long serialVersionUID = 1L;

// Width of the matrix (number of tiles in width)
private long numTilesWide;

// Height of the matrix (number of tiles in height)
private long numTilesHigh;

private double resolution;

private double scaleDenom;

// The identifier for the Grid
private String name;

private List<String> keywords = new ArrayList<>();

private String abstractText;

private String title;

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Grid)) return false;
Expand All @@ -53,6 +64,11 @@ public int hashCode() {
return Objects.hash(numTilesWide, numTilesHigh, resolution, scaleDenom, name);
}

/**
* Returns the identifier for the Grid
*
* @return the identifier
*/
public String getName() {
return name;
}
Expand All @@ -76,7 +92,11 @@ public void setScaleDenominator(double scaleDenom) {
this.scaleDenom = scaleDenom;
}

/** @param name the name to set */
/**
* Sets the identifier for the Grid
*
* @param name the identifier to set
*/
public void setName(String name) {
this.name = name;
}
Expand All @@ -101,6 +121,61 @@ public void setNumTilesHigh(long numTilesHigh) {
this.numTilesHigh = numTilesHigh;
}

/**
* Gets the keywords for the Grid
*
* @return the keywords
*/
public List<String> getKeywords() {
return keywords;
}

/**
* Sets the keywords for the Grid
*
* @param keywords the keywords to set
*/
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}

/**
* Gets the abstract for this Grid
*
* @return the abstract text
*/
public String getAbstractText() {
return abstractText;
}

/**
* Sets the abstract for this Grid
*
* @param abstractText the text to set as the abstract
*/
public void setAbstractText(String abstractText) {
this.abstractText = abstractText;
}

/**
* Gets the title for the Grid. Use {@link #getName()} to get the identifier
*
* @return the title for the grid
*/
public String getTitle() {
return title;
}

/**
* Sets the title for the Grid. This is different to the identifier which should be set using
* {@link #setName(String)}
*
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}

@Override
public String toString() {
return new StringBuilder(getClass().getSimpleName())
Expand Down
68 changes: 61 additions & 7 deletions geowebcache/core/src/main/java/org/geowebcache/grid/GridSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*/
package org.geowebcache.grid;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
Expand All @@ -24,6 +26,7 @@
/** A grid set configuration */
public class GridSet implements Info {

// The identifier for the GridSet
private String name;

private SRS srs;
Expand Down Expand Up @@ -55,9 +58,13 @@ public class GridSet implements Info {

private String description;

private List<String> keywords = new ArrayList<>();

private String title;

/**
* {@code true} if the resolutions are preserved and the scaleDenominators calculated, {@code
* false} if the resolutions are calculated based on the sacale denominators.
* false} if the resolutions are calculated based on the scale denominators.
*/
private boolean resolutionsPreserved;

Expand All @@ -80,6 +87,8 @@ public GridSet(GridSet g) {
this.gridLevels = g.gridLevels;
this.description = g.description;
this.resolutionsPreserved = g.resolutionsPreserved;
this.keywords = g.keywords;
this.title = g.title;
}

/** @return the originalExtent */
Expand All @@ -94,7 +103,7 @@ void setOriginalExtent(BoundingBox originalExtent) {

/**
* @return {@code true} if the resolutions are preserved and the scaleDenominators calculated,
* {@code false} if the resolutions are calculated based on the sacale denominators.
* {@code false} if the resolutions are calculated based on the scale denominators.
*/
public boolean isResolutionsPreserved() {
return resolutionsPreserved;
Expand All @@ -103,7 +112,7 @@ public boolean isResolutionsPreserved() {
/**
* @param resolutionsPreserved {@code true} if the resolutions are preserved and the
* scaleDenominators calculated, {@code false} if the resolutions are calculated based on
* the sacale denominators.
* the scale denominators.
*/
void setResolutionsPreserved(boolean resolutionsPreserved) {
this.resolutionsPreserved = resolutionsPreserved;
Expand Down Expand Up @@ -412,7 +421,7 @@ void setGridLevels(Grid[] gridLevels) {
}

/**
* The base cordinates in x/y order, used to map tile indexes to coordinate bounding boxes.
* The base coordinates in x/y order, used to map tile indexes to coordinate bounding boxes.
* These can either be top left or bottom left, so must be kept private.
*
* <p>This is a derived property of {@link #getOriginalExtent()} and {@link
Expand Down Expand Up @@ -464,12 +473,20 @@ void setPixelSize(double pixelSize) {
this.pixelSize = pixelSize;
}

/** @return the name */
/**
* Returns the identifier for the GridSet
*
* @return the identifier
*/
public String getName() {
return name;
}

/** @param name the name to set */
/**
* Sets the identifier for the GridSet
*
* @param name the identifier to set
*/
void setName(String name) {
this.name = name;
}
Expand Down Expand Up @@ -513,7 +530,44 @@ void setTileHeight(int tileHeight) {
}

/**
* Evaluates wheter this GridSet is different enough from {@code another} so that if this
* Gets the keywords for the GridSet
*
* @return the keywords
*/
public List<String> getKeywords() {
return keywords;
}

/**
* Sets the keywords for the GridSet
*
* @param keywords the keywords to set
*/
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}

/**
* Gets the title for the GridSet. Use {@link #getName()} to get the identifier
*
* @return the title for the gridset
*/
public String getTitle() {
return title;
}

/**
* Sets the title for the Gridset. This is different to the identifier which should be set using
* {@link #setName(String)}
*
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}

/**
* Evaluates whether this GridSet is different enough from {@code another} so that if this
* GridSet were replaced by {@code another} all layers referencing this GridSet should be
* truncated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,30 @@ private static GridSet baseGridSet(String name, SRS srs, int tileWidth, int tile
}

/**
* Note that you should provide EITHER resolutions or scales. Providing both will cause a
* precondition violation exception.
* Creates a gridset and automatically calculates the grids (scale sets) based on either
* resolutions or on scaleDenoms .Note that you should provide EITHER resolutions or scales.
* Providing both will cause a precondition violation exception.
*
* @param extent the bounding box for the gridset
* @param resolutions the resolutions of each grid. Set to {@code null} if grids should be
* calculated using scaleDenoms instead. Resolutions should be in metres per pixel
* @param scaleDenoms the scale Denominators of each grid. Set to {@code null} if grids should
* be calculated using resolutions instead
* @param pixelSize the size of a pixel in meters. Used when calculating grids using scale
* denominators
* @param scaleNames the names of each grid
* @param tileWidth the width of each tile in pixels
* @param tileHeight the height of each tile in pixels
* @param alignTopLeft Indicates how the matrix should be aligned within the extent, where
* {@code true} means that the matrix should be aligned with the top left of the extent and
* {@code false} means that it should be aligned with the bottom left.
* @param metersPerUnit the number of meters per unit in the scale denominator. e.g. if the
* scale is 1/28000, then this should be set to 1.0 and the relevant scaleDenom will be
* 28000
* @param name the name to be applied to the gridset
* @param srs the srs associated with this gridset
* @param yCoordinateFirst used to set the {@link GridSet#setyCoordinateFirst} value
* @return the created Gridset
*/
public static GridSet createGridSet(
final String name,
Expand Down Expand Up @@ -184,6 +206,26 @@ public static GridSet createGridSet(
return gridSet;
}

/**
* Creates a gridset with grids based on the extent and number of levels required.
*
* @param name the name to be applied to the gridset
* @param srs the srs associated with this gridset
* @param extent the bounding box for the gridset
* @param alignTopLeft Indicates how the matrix should be aligned within the extent, where
* {@code true} means that the matrix should be aligned with the top left of the extent and
* {@code false} means that it should be aligned with the bottom left.
* @param levels the number of levels that the gridset should have
* @param metersPerUnit the number of meters per unit in the scale denominator. e.g. if the
* scale is 1/28000, then this should be set to 1.0 and the relevant scaleDenom will be
* 28000
* @param pixelSize the size of a pixel in meters. Used when calculating grids using scale
* denominators
* @param tileWidth the width of each tile in pixels
* @param tileHeight the height of each tile in pixels
* @param yCoordinateFirst used to set the {@link GridSet#setyCoordinateFirst} value
* @return the created GridSet
*/
public static GridSet createGridSet(
final String name,
final SRS srs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ private void serviceIdentification(XMLBuilder xml, ServiceInformation servInfo)

if (servInfo != null && servInfo.getKeywords() != null) {
xml.indentElement("ows:Keywords");
Iterator<String> keywordIter = servInfo.getKeywords().iterator();
while (keywordIter.hasNext()) {
appendTag(xml, "ows:Keyword", keywordIter.next(), null);
for (String s : servInfo.getKeywords()) {
appendTag(xml, "ows:Keyword", s, null);
}
xml.endElement();
}
Expand Down Expand Up @@ -763,12 +762,28 @@ private void layerResourceUrlsGen(XMLBuilder xml, String format, String type, St

private void tileMatrixSet(XMLBuilder xml, GridSet gridSet) throws IOException {
xml.indentElement("TileMatrixSet");

if (gridSet.getTitle() != null) {
xml.simpleElement("ows:Title", gridSet.getTitle(), true);
}
if (gridSet.getDescription() != null) {
xml.simpleElement("ows:Abstract", gridSet.getDescription(), true);
}
if (!gridSet.getKeywords().isEmpty()) {
xml.indentElement("ows:Keywords");
for (String s : gridSet.getKeywords()) {
appendTag(xml, "ows:Keyword", s, null);
}
xml.endElement();
}

xml.simpleElement("ows:Identifier", gridSet.getName(), true);
// If the following is not good enough, please get in touch and we will try to fix it :)
xml.simpleElement(
"ows:SupportedCRS", "urn:ogc:def:crs:EPSG::" + gridSet.getSrs().getNumber(), true);
// TODO detect these str.append("
// <WellKnownScaleSet>urn:ogc:def:wkss:GlobalCRS84Pixel</WellKnownScaleSet>\n");

for (int i = 0; i < gridSet.getNumLevels(); i++) {
double[] tlCoordinates = gridSet.getOrderedTopLeftCorner(i);
tileMatrix(
Expand All @@ -790,14 +805,32 @@ private void tileMatrix(
int tileHeight,
boolean scaleWarning)
throws IOException {

xml.indentElement("TileMatrix");
if (scaleWarning) {
xml.simpleElement(
"ows:Abstract",
"The grid was not well-defined, the scale therefore assumes 1m per map unit.",
true);
}

if (grid.getTitle() != null) {
xml.simpleElement("ows:Title", grid.getTitle(), true);
}
if (grid.getAbstractText() != null) {
xml.simpleElement("ows:Abstract", grid.getAbstractText(), true);
}

if (!grid.getKeywords().isEmpty()) {
xml.indentElement("ows:Keywords");
for (String s : grid.getKeywords()) {
appendTag(xml, "ows:Keyword", s, null);
}
xml.endElement();
}

xml.simpleElement("ows:Identifier", grid.getName(), true);

xml.simpleElement("ScaleDenominator", Double.toString(grid.getScaleDenominator()), true);
xml.indentElement("TopLeftCorner")
.text(Double.toString(tlCoordinates[0]))
Expand Down
Loading