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

Made changes to appropriate java files to fix raster download methods… #34

Open
wants to merge 5 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.InputStream;
import java.util.HashSet;

import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -58,16 +59,19 @@ public String createDownloadRequest() throws Exception {
SolrRecord layerInfo = this.currentLayer.getLayerInfo();

Envelope env = describeLayerInfo.getLonLatEnvelope();
BoundingBox nativeBounds = new BoundingBox(env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY());
BoundingBox nativeLatLon = new BoundingBox(env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY());
logger.info("reqLatLon" + this.currentLayer.getRequestedBounds().toStringLatLon());
logger.info("natLatLon" + nativeBounds.toStringLatLon());
logger.info("natLatLon" + nativeLatLon.toStringLatLon());

BoundingBox bounds = nativeBounds.getIntersection(this.currentLayer.getRequestedBounds());
BoundingBox bounds = nativeLatLon.getIntersection(this.currentLayer.getRequestedBounds());
logger.info("intLatLon" + bounds.toStringLatLon());

String layerName = this.currentLayer.getLayerNameNS();

// BEN ADDED...
Envelope nativeEnv = describeLayerInfo.getNativeEnvelope();
BoundingBox nativeBbox = new BoundingBox(nativeEnv.getMinX(), nativeEnv.getMinY(), nativeEnv.getMaxX(), nativeEnv.getMaxY());
//

String layerName = this.currentLayer.getLayerNameNS();

/*
String epsgCode = describeLayerInfo.get("SRS");
Expand Down Expand Up @@ -129,8 +133,10 @@ public String createDownloadRequest() throws Exception {
*/
int epsgCode = 4326;
String format = "geotiff";
return WcsGetCoverage1_0_0.createWcsGetCoverageRequest(layerName, describeLayerInfo, bounds, epsgCode, format);
//return getCoverageRequest;
// BEN ADDED nativeBboxValues
return WcsGetCoverage1_0_0.createWcsGetCoverageRequest(layerName, describeLayerInfo, bounds, epsgCode, format, nativeBbox);
//
//return getCoverageRequest;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fasterxml.jackson.core.JsonParseException;

public class WmsDownloadMethod extends AbstractDownloadMethod implements PerLayerDownloadMethod {
private static final Double MAX_AREA = 1800.0 * 1800.0; //should be within recommended geoserver memory settings.
private static final Double MAX_AREA = 1800.0 * 1800.0;
private static final Boolean INCLUDES_METADATA = false;
final Logger logger = LoggerFactory.getLogger(this.getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public class CoverageOffering1_0_0 implements OwsDescribeInfo{
String label;

Envelope lonLatEnvelope;

//Ben ADDED
Envelope nativeEnvelope;
//
List<String> keywords;

RectifiedGrid rectifiedGrid;
Expand Down Expand Up @@ -105,6 +107,14 @@ public Envelope getLonLatEnvelope() {
public void setLonLatEnvelope(Envelope lonLatEnvelope) {
this.lonLatEnvelope = lonLatEnvelope;
}
// BEN ADDED
public Envelope getNativeEnvelope() {
return nativeEnvelope;
}
public void setNativeEnvelope(Envelope nativeEnvelope) {
this.nativeEnvelope = nativeEnvelope;
}
//
public List<String> getKeywords() {
return keywords;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;

import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static Envelope parseLonLatEnvelope(Node lonLatEnvelopeNode){
return new Envelope(minX, minY, maxX, maxY, srsName);

}

public static List<String> parseKeywords(Node keywordsNode){

NodeList keywordNodes = keywordsNode.getChildNodes();
Expand Down Expand Up @@ -230,6 +231,10 @@ public OwsInfo parseResponse(InputStream inputStream) throws Exception {
} else if (nodeName.equalsIgnoreCase("domainSet")){
Node sdNode = OgpXmlUtils.getChildNode(currentDetail, "spatialDomain");
Node rgNode = OgpXmlUtils.getChildNode(sdNode, "RectifiedGrid");
//BEN ADDED
Node nativeEnvelopeNode = OgpXmlUtils.getChildNode(sdNode,"Envelope");
coverageOffering.setNativeEnvelope(parseLonLatEnvelope(nativeEnvelopeNode));
//
coverageOffering.setRectifiedGrid(parseRectifiedGrid(rgNode));
} else if (nodeName.equalsIgnoreCase("rangeSet")){
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;

// BEN ADDED
import java.util.HashMap;
//
import org.geotools.factory.Hints;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.ReferencingFactoryFinder;
Expand Down Expand Up @@ -30,8 +33,8 @@ public static Boolean supports(List<String> supportedList, String testValue){
}
return false;
}
public static String createWcsGetCoverageRequest(String layerName, CoverageOffering1_0_0 coverageOffering, BoundingBox bounds, int epsgCode, String outputFormat) throws Exception {

public static String createWcsGetCoverageRequest(String layerName, CoverageOffering1_0_0 coverageOffering, BoundingBox bounds, int epsgCode, String outputFormat, BoundingBox nativeBbox) throws Exception {
//http://data.fao.org/maps/wcs?service=WCS&version=1.0.0&request=GetCoverage&coverage=lus_mna_31661&bbox=-13.166733,39.766613,12.099957,63.333236&crs=EPSG:4326&format=geotiff&width=917&height=331

List<String> supportedFormats = coverageOffering.getSupportedFormats();
Expand All @@ -46,23 +49,67 @@ public static String createWcsGetCoverageRequest(String layerName, CoverageOffer
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
CoordinateReferenceSystem sourceCRS = factory.createCoordinateReferenceSystem("EPSG:4326");


//The bounding box is created in EPSG 4326. The line below takes the corrdinates given and references to the sourceCRS (EPSG:4326).
//The envelope is then transformed to the native (targetCRS) bounds below.
ReferencedEnvelope envelope = new ReferencedEnvelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY(), sourceCRS);
logger.info("requested Bounds: " + OgpUtils.referencedEnvelopeToString(envelope));

// Transform using 10 sample points around the envelope

CoordinateReferenceSystem targetCRS = factory.createCoordinateReferenceSystem(coverageOffering.getSupportedCRSs().get(0));

ReferencedEnvelope result = envelope.transform(targetCRS, true, 10);

String getCoverageRequest = "service=WCS&version=" + VERSION +
ReferencedEnvelope nativeRefEnv = new ReferencedEnvelope(nativeBbox.getMinX(), nativeBbox.getMaxX(), nativeBbox.getMinY(), nativeBbox.getMaxY(), targetCRS);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need generateSize. The getCoverageRequest string is composed near the end of the file.

Double resX = coverageOffering.getRectifiedGrid().getResx();
Double resY = coverageOffering.getRectifiedGrid().getResy();

Double xMin, yMin, xMax, yMax;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following section is where the bounding box is snapped to whole pixels rather than arbitrarily cutting through them.

if ( nativeRefEnv.getMinimum(0) > result.getMinimum(0)){
xMin = nativeRefEnv.getMinimum(0);
} else {
Double x_a = (Math.abs(result.getMinimum(0) - nativeRefEnv.getMinimum(0)))/resX;
xMin = nativeRefEnv.getMinimum(0) + (x_a.intValue() * resX); }

if ( nativeRefEnv.getMinimum(1) > result.getMinimum(1)){
yMin = nativeRefEnv.getMinimum(1);
} else {
Double y_a = (Math.abs(result.getMinimum(1) - nativeRefEnv.getMinimum(1)))/resY;
yMin = nativeRefEnv.getMinimum(1) + (y_a.intValue() * resY); }


if ( nativeRefEnv.getMaximum(0) < result.getMaximum(0)){
xMax = nativeRefEnv.getMaximum(0);
} else {
Double x_b = (Math.abs(result.getMaximum(0) - nativeRefEnv.getMaximum(0)))/resX;
xMax = nativeRefEnv.getMaximum(0) - (x_b.intValue() * resX); }


if ( nativeRefEnv.getMaximum(1) < result.getMaximum(1)){
yMax = nativeRefEnv.getMaximum(1);
} else {
Double y_b = (Math.abs(result.getMaximum(1) - nativeRefEnv.getMaximum(1)))/resY;
yMax = nativeRefEnv.getMaximum(1) - (y_b.intValue() * resY); }

String bbox = "&bbox=" + Double.toString(xMin) + "," + Double.toString(yMin) + "," + Double.toString(xMax) + "," + Double.toString(yMax);
Double dwidth = (Math.abs(xMax - xMin))/resX;
Double dheight = (Math.abs(yMax - yMin))/resY;
int width = dwidth.intValue();
int height = dheight.intValue();

String widthHeight = "&width=" + width + "&height=" + height;

String getCoverageRequest = "service=WCS&version=" + VERSION +
"&request=GetCoverage&coverage=" + layerName +
"&bbox=" + OgpUtils.referencedEnvelopeToString(result) +
bbox +
//"&bbox=" + OgpUtils.referencedEnvelopeToString(result) +
// "&bbox=" + OgpUtils.referencedEnvelopeToString(result) +
"&crs=" + coverageOffering.getSupportedCRSs().get(0) +
"&format=" + outputFormat;

getCoverageRequest += generateSize(coverageOffering.getRectifiedGrid());

"&format=" + outputFormat +
widthHeight;

return getCoverageRequest;
}

Expand Down Expand Up @@ -94,5 +141,35 @@ private static String generateSize(RectifiedGrid rgrid) throws Exception{

return size;
}
/*
private static String generateSize(RectifiedGrid rgrid) throws Exception{
Integer width = rgrid.getWidth();
Integer height = rgrid.getHeight();

String size = "&";

if (width.equals(null) || height.equals(null)){
Double resx = rgrid.getResx();
Double resy = rgrid.getResy();
if (!resx.isNaN() && !resy.isNaN()) {
size += "resx=";
size += Double.toString(resx);
size += "&resy=";
size += Double.toString(resy);
} else {
throw new Exception("invalid describe coverage response....could not form getCoverage request.");
}

} else {
size += "width=";
size += Integer.toString(width);
size += "&height=";
size += Integer.toString(height);
}


return size;
}*/


}
6 changes: 5 additions & 1 deletion geoportal_1/src/main/webapp/resources/css/structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -1820,4 +1820,8 @@ zoom: 1;
/*border-bottom: 8px solid #4B8ACF;*/
top: -11px;
z-index: 999;
}
}

.previewedLayers .tableRow.rowHover {
cursor: all-scroll;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (typeof OpenGeoportal.Views === 'undefined') {
OpenGeoportal.Views.LayerRow = Backbone.View.extend({
tagName : "div",
className : "tableRow",
id : function() { return this.model.get("LayerId") },
events : {
"click .viewMetadataControl" : "viewMetadata",
"click .previewControl" : "togglePreview",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ OpenGeoportal.Views.SearchResultsTable = OpenGeoportal.Views.LayerTable
this.setFrameHeight();
var scrollTarget$ = this.$el.children(".tableWrapper").children(".rowContainer");
scrollTarget$.off("scroll").on("scroll", function(){that.watchScroll.apply(that, arguments);});
this.setSortableLayers();

},
prevScrollY: 0,
Expand Down Expand Up @@ -124,6 +125,35 @@ OpenGeoportal.Views.SearchResultsTable = OpenGeoportal.Views.LayerTable
$scrollTarget.height(ht);
},

setSortableLayers: function(){
if (this.$(".previewedLayers .rowContainer").children().size() > 0) {
this.$(".previewedLayers").css("border", "1px solid #828282");
} else {
this.$(".previewedLayers").css("border", "none");
};

this.$(".previewedLayers .rowContainer").sortable({
connectWith: ".sortable",
stop:
function(event, ui) {
var numPreviewedLayers = $(".previewedLayers .rowContainer").length;
$(".previewedLayers .rowContainer").children(".tableRow").each( function(){
var layerId = $(this).attr("id")
var index = $(this).index();

var zindex = (numPreviewedLayers - index) * 5 + 335 //openLayers2 sets start of layer index to 335 and increments by 5. Using this to stay equation to consistent.

jQuery(document).trigger("map.zIndexChange", {
zIndex : zindex,
LayerId: layerId
});
});
}

});
this.$(".previewedLayers .rowContainer").disableSelection();
},

fireSearchHandler: function(){
var that = this;
jQuery(document).on("fireSearch", function(){
Expand Down