Skip to content

Commit

Permalink
handle situation where first layer is raster
Browse files Browse the repository at this point in the history
  • Loading branch information
turingtestfail committed Feb 25, 2025
1 parent 90ec79d commit 2cbe9d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ public static Mapml featureCollectionToMapML(

// Some stuff we are getting from the first layer
LayerInfo firstLayerInfo = featureCollectionInfoSimplifiers.get(0).getLayerInfo();
ResourceInfo resourceInfo = firstLayerInfo.getResource();
MetadataMap layerMeta = resourceInfo.getMetadata();
CoverageInfo fallbackCoverageInfo = null;
MetadataMap layerMeta = null;
if (firstLayerInfo == null) {
fallbackCoverageInfo = featureCollectionInfoSimplifiers.get(0).getCoverageInfo();
layerMeta = fallbackCoverageInfo.getMetadata();
} else {
ResourceInfo resourceInfo = firstLayerInfo.getResource();
layerMeta = resourceInfo.getMetadata();
}

// build the mapML doc
Mapml mapml = new Mapml();
Expand All @@ -138,7 +145,7 @@ public static Mapml featureCollectionToMapML(
meta.setHttpEquiv("Content-Type");
meta.setContent(MapMLConstants.MAPML_MIME_TYPE);
metas.add(meta);
Set<Meta> projectionAndExtent = deduceProjectionAndExtent(requestCRS, firstLayerInfo);
Set<Meta> projectionAndExtent = deduceProjectionAndExtent(requestCRS, firstLayerInfo, fallbackCoverageInfo);
metas.addAll(projectionAndExtent);
List<Link> links = head.getLinks();
if (alternateProjections != null) {
Expand Down Expand Up @@ -479,7 +486,7 @@ public static Mapml getEmptyMapML(LayerInfo layerInfo, CoordinateReferenceSystem
meta.setHttpEquiv("Content-Type");
meta.setContent(MapMLConstants.MAPML_MIME_TYPE);
metas.add(meta);
Set<Meta> projectionAndExtent = deduceProjectionAndExtent(requestCRS, layerInfo);
Set<Meta> projectionAndExtent = deduceProjectionAndExtent(requestCRS, layerInfo, null);
metas.addAll(projectionAndExtent);
List<Link> links = head.getLinks();

Expand Down Expand Up @@ -571,10 +578,12 @@ public static String getCSSStyles(Map<String, MapMLStyle> styles) {
* @param layerInfo metadata for the feature class
* @return
*/
private static Set<Meta> deduceProjectionAndExtent(CoordinateReferenceSystem requestCRS, LayerInfo layerInfo) {
private static Set<Meta> deduceProjectionAndExtent(
CoordinateReferenceSystem requestCRS, LayerInfo layerInfo, CoverageInfo fallbackCoverageInfo) {
Set<Meta> metas = new HashSet<>();
TiledCRSParams tcrs = null;
CoordinateReferenceSystem sourceCRS = layerInfo.getResource().getCRS();
CoordinateReferenceSystem sourceCRS =
layerInfo != null ? layerInfo.getResource().getCRS() : fallbackCoverageInfo.getCRS();
CoordinateReferenceSystem responseCRS = sourceCRS;
String sourceCRSCode = CRS.toSRS(sourceCRS);
String responseCRSCode = sourceCRSCode;
Expand Down Expand Up @@ -610,7 +619,7 @@ private static Set<Meta> deduceProjectionAndExtent(CoordinateReferenceSystem req
projection.setContent(crs.equalsIgnoreCase("gcrs") ? cite + ":" + responseCRSCode : responseCRSCode);
coordinateSystem.setContent(crs);
}
extent.setContent(getExtent(layerInfo, responseCRSCode, responseCRS));
extent.setContent(getExtent(layerInfo, fallbackCoverageInfo, responseCRSCode, responseCRS));
metas.add(projection);
metas.add(coordinateSystem);
metas.add(extent);
Expand All @@ -624,9 +633,20 @@ private static Set<Meta> deduceProjectionAndExtent(CoordinateReferenceSystem req
* @return
*/
private static String getExtent(
LayerInfo layerInfo, String responseCRSCode, CoordinateReferenceSystem responseCRS) {
LayerInfo layerInfo,
CoverageInfo fallbackCoverageInfo,
String responseCRSCode,
CoordinateReferenceSystem responseCRS) {
String extent = "";
ResourceInfo r = layerInfo.getResource();
ReferencedEnvelope nativeBbox = null;
ReferencedEnvelope latLonBbox = null;
if (layerInfo != null) {
nativeBbox = layerInfo.getResource().getNativeBoundingBox();
latLonBbox = layerInfo.getResource().getLatLonBoundingBox();
} else if (fallbackCoverageInfo != null) {
nativeBbox = fallbackCoverageInfo.getNativeBoundingBox();
latLonBbox = fallbackCoverageInfo.getLatLonBoundingBox();
}
ReferencedEnvelope re;
String gcrsFormat =
"top-left-longitude=%1$.6f,top-left-latitude=%2$.6f,bottom-right-longitude=%3$.6f,bottom-right-latitude=%4$.6f";
Expand All @@ -637,14 +657,16 @@ private static String getExtent(
TiledCRSParams tcrs = TiledCRSConstants.lookupTCRSParams(responseCRSCode);
try {
if (responseCRS instanceof GeodeticCRS) {
re = r.getLatLonBoundingBox();
re = latLonBbox;
assert re != null;
minLong = re.getMinX();
minLat = re.getMinY();
maxLong = re.getMaxX();
maxLat = re.getMaxY();
extent = String.format(gcrsFormat, minLong, maxLat, maxLong, minLat);
} else {
re = r.boundingBox().transform(responseCRS, true);
assert nativeBbox != null;
re = nativeBbox.transform(responseCRS, true);
minEasting = re.getMinX();
minNorthing = re.getMinY();
maxEasting = re.getMaxX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.geoserver.mapml.xml.Mapml;
import org.geoserver.platform.ServiceException;
import org.geoserver.wms.GetMapRequest;
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.WMSMapContent;
import org.geotools.api.data.FeatureSource;
import org.geotools.api.data.Query;
Expand Down Expand Up @@ -142,10 +141,6 @@ public void setSkipHeadStyles(boolean skipHeadStyles) {
* @throws IOException If an error occurs while producing the map
*/
public Mapml getMapMLDocument() throws IOException {
if (!getMapRequest.getLayers().isEmpty()
&& MapLayerInfo.TYPE_VECTOR != getMapRequest.getLayers().get(0).getType()) {
throw new ServiceException("MapML WMS Feature format does not currently support non-vector layers.");
}
List<MapMLFeatureUtil.FeatureCollectionInfoSimplifier> featureCollectionInfoSimplifiers = new ArrayList<>();
int i = 0;
for (Layer layer : mapContent.layers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.geoserver.ows.Request;
import org.geoserver.platform.ServiceException;
import org.geoserver.wms.GetMapOutputFormat;
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.MapProducerCapabilities;
import org.geoserver.wms.WMS;
import org.geoserver.wms.WMSMapContent;
Expand Down Expand Up @@ -62,11 +61,6 @@ public WebMap produceMap(WMSMapContent mapContent) throws ServiceException, IOEx
Request request = Dispatcher.REQUEST.get();
Mapml mapMLDocument;
if (isFeaturesRequest(request)) {
if (!mapContent.getRequest().getLayers().isEmpty()
&& MapLayerInfo.TYPE_VECTOR
!= mapContent.getRequest().getLayers().get(0).getType()) {
throw new ServiceException("MapML WMS Feature format does not currently support non-vector layers.");
}
List<Query> queries = StyleQueryUtil.getStyleQuery(mapContent.layers(), mapContent);
MapMLFeaturesBuilder builder =
new MapMLFeaturesBuilder(mapContent, geoServer, queries, request.getHttpRequest());
Expand Down

0 comments on commit 2cbe9d7

Please sign in to comment.