Updated layer preview

This commit is contained in:
Francesco Mangiacrapa 2023-12-19 15:32:34 +01:00
parent 2bb81cbd76
commit 96c19ca6dd
7 changed files with 224 additions and 1290 deletions

View File

@ -35,6 +35,7 @@ import org.gcube.application.geoportaldatamapper.exporter.beans.Credits;
import org.gcube.application.geoportaldatamapper.exporter.beans.PDFExporterConfig;
import org.gcube.application.geoportaldatamapper.exporter.beans.PageNumber;
import org.gcube.application.geoportaldatamapper.exporter.beans.Watermarker;
import org.gcube.application.geoportaldatamapper.exporter.gis.BBOXConverter;
import org.gcube.application.geoportaldatamapper.exporter.gis.Recalculate_WGS84_Offset;
import org.gcube.application.geoportaldatamapper.reader.MapBoxEndpointReader;
import org.gcube.application.geoportaldatamapper.reader.ServiceAccessPoint;
@ -75,6 +76,7 @@ import com.itextpdf.layout.Canvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.Style;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.Image;
@ -641,7 +643,7 @@ public class Geoportal_PDF_Exporter {
Paragraph paragraph = new Paragraph().add(sectionView.getSectionTitle()).setFont(bold)
.setFontSize(FONT_SIZE_SECTION_TITLE);
paragraph.setMarginTop(PARAGRAPH_MARGIN_TOP);
// document.add(new AreaBreak());
document.add(new AreaBreak());
document.add(paragraph);
LOG.debug("displayAsGallery the: " + sectionView);
for (SubDocumentView subDocumentView : subDocuments) {
@ -687,7 +689,7 @@ public class Geoportal_PDF_Exporter {
Paragraph paragraph = new Paragraph().add(sectionView.getSectionTitle()).setFont(bold)
.setFontSize(FONT_SIZE_SECTION_TITLE);
paragraph.setMarginTop(PARAGRAPH_MARGIN_TOP);
// document.add(new AreaBreak());
document.add(new AreaBreak());
document.add(paragraph);
LOG.trace("displayAsMapOfLayers the: " + sectionView);
for (SubDocumentView subDocumentView : subDocuments) {
@ -710,36 +712,6 @@ public class Geoportal_PDF_Exporter {
wmsLink = URLParserUtil.setValueOfParameter("format", wmsLink, "image/png", true);
String source_bbox = URLParserUtil.extractValueOfParameterFromURL("bbox", wmsLink);
String wmsVersion = URLParserUtil.extractValueOfParameterFromURL("version", wmsLink);
/*
Double expWidth = 500.0;
Double expHeight = 500.0;
double bboxOffset = 0.01;
String parmBBOX = BBOXConverter.bboxWithOffset(wmsVersion, bbox, bboxOffset);
// Calculating bounding box dimension
List<Double> bbox3857_BB = CoordinatesConverter.toEPSG3857_BBOX(parmBBOX);
String bbox3857 = CoordinatesConverter.toString(bbox3857_BB);
LOG.debug("toEPSG3857_BBOX: " + bbox3857);
ArrayList<Double> diff = CoordinatesConverter.diffBBox(bbox3857);
LOG.debug("BoudingBox width - height: " + diff);
double width = diff.get(0);
double height = diff.get(1);
double ratio = width / height;
LOG.trace("bbox width: " + width);
LOG.trace("bbox heigth: " + height);
LOG.trace("bbox ratio: " + ratio);
// Calculating width/height ratio
if (ratio > 1) {
expWidth = expWidth * ratio;
} else {
expHeight = expHeight * ratio;
}
int aspectratioWidth = expWidth.intValue();
int aspectratioHeight = expHeight.intValue();*/
double bboxOffset = 0.0;
LOG.trace("source_bbox: " + source_bbox);
@ -749,20 +721,9 @@ public class Geoportal_PDF_Exporter {
LOG.trace("source heigth: " + recalculate.getAspectratioHeight());
LOG.trace("source ratio: " + recalculate.getRatio_Width_Height());
LOG.trace("source bbox: " + recalculate.getBboxWithOffset());
int height = recalculate.getAspectratioHeight();
int width = recalculate.getAspectratioWidth();
if (width < 100 || height < 100) {
bboxOffset = 0.00001;
} else if (width < 200 || height < 200) {
bboxOffset = 0.0001;
} else if (width < 500 || height < 500) {
bboxOffset = 0.001;
} else if (width < 1000 || height < 1000) {
bboxOffset = 0.01;
}
bboxOffset = BBOXConverter.bestBBOXOffset(wmsVersion, source_bbox);
//bboxOffset = 0.0001;
LOG.debug("applying offset: "+bboxOffset);
@ -773,7 +734,6 @@ public class Geoportal_PDF_Exporter {
LOG.trace("ratio: " + recalculate.getRatio_Width_Height());
LOG.trace("bbox with offset: " + recalculate.getBboxWithOffset());
int aspectratioWidth = recalculate.getAspectratioWidth();
int aspectratioHeight = recalculate.getAspectratioHeight();
String recaulculateBBOX = recalculate.getBboxWithOffset();
@ -787,16 +747,16 @@ public class Geoportal_PDF_Exporter {
wmsLinkTol += "&TRANSPARENT=TRUE";
LOG.trace("wmsLink aspect ratio link: " + wmsLink);
int maxWidthMap = 350;
int maxWidthMap = 300;
Image image2 = toImageFromLink(wmsLinkTol, null, null);
Image image2 = toImageFromLink(wmsLinkTol, maxWidthMap);
// MapBox static as background
String linkToMapBox = linkToMapBoxStaticMap(recaulculateBBOX,
aspectratioWidth + "x" + aspectratioHeight, sap);
LOG.trace("linkToMapBox: " + linkToMapBox);
Image backImg = toImageFromLink(linkToMapBox, null, null);
Image backImg = toImageFromLink(linkToMapBox, maxWidthMap);
Cell mapCell = new Cell();
mapCell.setMaxWidth(maxWidthMap);

View File

@ -5,18 +5,40 @@ import java.util.List;
import org.gcube.spatial.data.geoutility.shared.BBOX;
/**
* The Class BBOXConverter.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 18, 2023
*/
public class BBOXConverter {
Integer[] size = new Integer[2];
Double[] bbox = new Double[4];
public static final double EQUATOR = 40075016.68557849;
/**
* The Class BBOXPixel.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 18, 2023
*/
public static class BBOXPixel {
public double x;
public double y;
public double w;
public double h;
/**
* Instantiates a new BBOX pixel.
*
* @param x the x
* @param y the y
* @param w the w
* @param h the h
*/
public BBOXPixel(double x, double y, double w, double h) {
super();
this.x = x;
@ -25,6 +47,11 @@ public class BBOXConverter {
this.h = h;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -41,6 +68,13 @@ public class BBOXConverter {
}
}
/**
* Convert to pixel.
*
* @param size the size
* @param bbox the bbox
* @return the BBOX converter. BBOX pixel
*/
public static BBOXConverter.BBOXPixel convertToPixel(Integer[] size, Double[] bbox) {
double dw = 1. / size[0];
double dh = 1. / size[1];
@ -56,6 +90,13 @@ public class BBOXConverter {
}
/**
* Convert to coordinate.
*
* @param bboxP the bbox P
* @param size the size
* @return the bbox
*/
public static BBOX convertToCoordinate(BBOXPixel bboxP, Integer[] size) {
double h = bboxP.h;
@ -74,6 +115,14 @@ public class BBOXConverter {
}
/**
* Bbox with offset.
*
* @param wmsVersion the wms version
* @param bbox the bbox
* @param bboxOffset the bbox offset
* @return the string
*/
public static String bboxWithOffset(String wmsVersion, String bbox, double bboxOffset) {
BBOX.COORDINATE_FORMAT bboxFormat = wmsVersion.contains("1.3") ? BBOX.COORDINATE_FORMAT.YX
@ -85,7 +134,7 @@ public class BBOXConverter {
// double lowerYR = theBBOX.getLowerLeftY() - (theBBOX.getLowerLeftY()*bboxOffset/100);
// double upperXR = theBBOX.getUpperRightX() + (theBBOX.getUpperRightX()*bboxOffset/100);
// double upperYR = theBBOX.getUpperRightY() + (theBBOX.getUpperRightY()*bboxOffset/100);
double lowerXR = theBBOX.getLowerLeftX() - bboxOffset;
double lowerYR = theBBOX.getLowerLeftY() - bboxOffset;
double upperXR = theBBOX.getUpperRightX() + bboxOffset;
@ -94,6 +143,20 @@ public class BBOXConverter {
return BBOX.toBBOXString(new BBOX(lowerXR, lowerYR, upperXR, upperYR, ""), bboxFormat);
}
/**
* To BBOX.
*
* @param wmsVersion the wms version
* @param bbox the bbox
* @return the bbox
*/
public static BBOX toBBOX(String wmsVersion, String bbox) {
BBOX.COORDINATE_FORMAT bboxFormat = wmsVersion.contains("1.3") ? BBOX.COORDINATE_FORMAT.YX
: BBOX.COORDINATE_FORMAT.XY;
return new BBOX(bbox, bboxFormat);
}
/**
* Converts spherical web mercator to tile pixel X/Y at zoom level 0 for 256x256
* tile size and inverts y coordinates.
@ -109,8 +172,56 @@ public class BBOXConverter {
double pixelY2 = ((bbox.get(3) - (EQUATOR / 2.0)) / (EQUATOR / -256.0));
return Arrays.asList(pixelX1, pixelY1, pixelX2, pixelY2);
}
/**
* Bbox offset.
*
* @param cMin the c min
* @param cMax the c max
* @return the double
*/
public static Double bboxOffset(String cMin, String cMax) {
String bboxOffsetString = "0.";
int startIndex = cMax.indexOf(".") + 1;
int lenght = cMax.length();
if (startIndex < lenght) {
for (int i = startIndex; i < lenght; i++) {
if (cMin.charAt(i) == cMax.charAt(i)) {
bboxOffsetString += "0";
} else {
bboxOffsetString += "1";
break;
}
}
}else {
bboxOffsetString = "0.0"; //no offset
}
return Double.parseDouble(bboxOffsetString);
}
/**
* Best BBOX offset.
*
* @param wmsVersion the wms version
* @param source_bbox the source bbox
* @return the double
*/
public static Double bestBBOXOffset(String wmsVersion, String source_bbox) {
BBOX theBBOX = BBOXConverter.toBBOX(wmsVersion, source_bbox);
String xMin = new Double(theBBOX.getLowerLeftX()).toString();
String xMax = new Double(theBBOX.getUpperRightX()).toString();
Double offsetWidth = bboxOffset(xMin, xMax);
//System.out.println("offsetWidth: " + offsetWidth);
String yMin = new Double(theBBOX.getLowerLeftY()).toString();
String yMax = new Double(theBBOX.getUpperRightY()).toString();
Double offsetHeight = bboxOffset(yMax, yMin);
//System.out.println("offsetHeight: " + offsetHeight);
return offsetWidth < offsetHeight ? offsetWidth : offsetHeight;
}
}

View File

@ -13,8 +13,8 @@ public class Recalculate_WGS84_Offset {
private double bboxOffset;
private String bboxWithOffset;
public Double expWidth = 700.0;
public Double expHeight = 700.0;
public Double expWidth = 500.0;
public Double expHeight = 500.0;
private int aspectratioWidth;
private int aspectratioHeight;
@ -26,28 +26,26 @@ public class Recalculate_WGS84_Offset {
this.wmsVersion = wmsVersion;
this.sourceBBOX = bbox;
this.bboxOffset = bboxOffset;
LOG.trace("sourceBBOX: " + sourceBBOX);
this.bboxWithOffset = BBOXConverter.bboxWithOffset(wmsVersion, sourceBBOX, this.bboxOffset);
// Calculating bounding box dimension
List<Double> bbox3857_BB = CoordinatesConverter.toEPSG3857_BBOX(bboxWithOffset);
String bbox3857 = CoordinatesConverter.toString(bbox3857_BB);
List<Double> bbox3857_BB = WGS84_CoordinatesConverter.toEPSG3857_BBOX(bboxWithOffset);
String bbox3857 = WGS84_CoordinatesConverter.toString(bbox3857_BB);
LOG.debug("toEPSG3857_BBOX: " + bbox3857);
ArrayList<Double> diff = CoordinatesConverter.diffBBOX(bbox3857);
ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBOX(bbox3857);
LOG.debug("BoudingBox [width dimension, height dimension]: " + diff);
double width = diff.get(0);
double height = diff.get(1);
// Calculating width/height ratio
ratio_Width_Height = width / height;
LOG.trace("bbox width: " + width);
LOG.trace("bbox heigth: " + height);
LOG.trace("bbox ratio: " + ratio_Width_Height);
// Calculating width/height ratio
if (ratio_Width_Height > 1) {
expWidth = expWidth * ratio_Width_Height;
} else {
expHeight = expHeight * ratio_Width_Height;
}
LOG.debug("bbox ratio: " + ratio_Width_Height);
//resizing width according to ratio width/height
expWidth = expWidth * ratio_Width_Height;
this.aspectratioWidth = expWidth.intValue();
LOG.debug("aspectratioWidth: " + aspectratioWidth);
this.aspectratioHeight = expHeight.intValue();

View File

@ -5,18 +5,18 @@ import java.util.Arrays;
import java.util.List;
/**
* The Class CoordinatesConverter_Tests.
* The Class WGS84_CoordinatesConverter.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 15, 2023
* Dec 18, 2023
*/
public class CoordinatesConverter {
public class WGS84_CoordinatesConverter {
private static double EARTH_RADIUS = 6378137.0;
/**
* To epsg 3857.
* From 4326 To epsg 3857.
*
* @param coordinates the coordinates as long/lat
* @return the list
@ -28,7 +28,7 @@ public class CoordinatesConverter {
}
/**
* To 4326.
* From 3857 To 4326.
*
* @param coordinates the coordinates as long/lat
* @return the list
@ -40,7 +40,7 @@ public class CoordinatesConverter {
}
/**
* To EPSG 3857 BBOX.
* From 4326 To EPSG 3857 BBOX.
*
* @param bbox the bbox
* @return the list
@ -67,9 +67,9 @@ public class CoordinatesConverter {
public static String toString(List<Double> bbox) {
return String.format("%s,%s,%s,%s", bbox.get(0), bbox.get(1), bbox.get(2), bbox.get(3));
}
/**
* To EPSG 4326 BBOX.
* From 3857 To EPSG 4326 BBOX.
*
* @param bbox the bbox
* @return the list
@ -88,7 +88,7 @@ public class CoordinatesConverter {
}
/**
* Diff B box.
* Diff BBOX.
*
* @param bbox the bbox
* @return the array list

View File

@ -1,51 +1,14 @@
import java.util.ArrayList;
import org.gcube.application.geoportaldatamapper.exporter.gis.CoordinatesConverter;
import org.gcube.application.geoportaldatamapper.exporter.gis.WGS84_CoordinatesConverter;
import org.gcube.spatial.data.geoutility.shared.BBOX;
import org.gcube.application.geoportaldatamapper.exporter.gis.BBOXConverter;
import org.gcube.application.geoportaldatamapper.exporter.gis.Recalculate_WGS84_Offset;
public class CoordinatesConverter_Tests {
private static double EARTH_RADIUS = 6378137.0;
// public static void main(String[] args) {
//
// // double bboxOffset = 0.003;
// String theBBOX = "15.208508,41.442976,15.209360,41.443437";
// double bboxOffset = 0.01; // no offset
// double lowerXR = theBBOX.getLowerLeftX() - bboxOffset;
// double lowerYR = theBBOX.getLowerLeftY() - bboxOffset;
// double upperXR = theBBOX.getUpperRightX() + bboxOffset;
// double upperYR = theBBOX.getUpperRightY() + bboxOffset;
//
// String parmBBOX = BBOX.toBBOXString(new BBOX(lowerXR, lowerYR, upperXR, upperYR, ""),
// bboxFormat);
//
// // Calculating bounding box dimension
// String bbox3857 = CoordinatesConverter.toEPSG3857_BBOX(parmBBOX);
// LOG.debug("toEPSG3857_BBOX: " + bbox3857);
// ArrayList<Double> diff = CoordinatesConverter.diffBBox(bbox3857);
// LOG.debug("BoudingBox width - height: " + diff);
// double width = diff.get(0);
// double height = diff.get(1);
// double ratio = width / height;
// LOG.trace("bbox width: " + width);
// LOG.trace("bbox heigth: " + height);
// LOG.trace("bbox ratio: " + ratio);
//
// // Calculating width/height ratio
// if (ratio > 1) {
// expWidth = expWidth * ratio;
// } else {
// expHeight = expHeight * ratio;
// }
//
// int aspectratioWidth = expWidth.intValue();
// int aspectratioHeight = expHeight.intValue();
//
// }
public static void main(String[] args) {
// String bbox = "14.350604,40.632238,14.353074,40.634530";
@ -63,15 +26,28 @@ public class CoordinatesConverter_Tests {
int height = recalculate.getAspectratioHeight();
int width = recalculate.getAspectratioWidth();
ArrayList<Double> diff = CoordinatesConverter.diffBBOX(source_bbox);
System.out.println("diff WGS84: "+diff);
ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBOX(source_bbox);
System.out.println("diff WGS84: " + diff);
BBOX theBBOX = BBOXConverter.toBBOX(wmsVersion, source_bbox);
String xMin = new Double(theBBOX.getLowerLeftX()).toString();
String xMax = new Double(theBBOX.getUpperRightX()).toString();
Double offsetWidth = BBOXConverter.bboxOffset(xMin, xMax);
System.out.println("offsetWidth: " + offsetWidth);
String yMin = new Double(theBBOX.getLowerLeftY()).toString();
String yMax = new Double(theBBOX.getUpperRightY()).toString();
Double offsetHeight = BBOXConverter.bboxOffset(yMax, yMin);
System.out.println("offsetHeight: " + offsetHeight);
// int expWidth = getExponentForNumber(diff.get(0));
// int expHeight = getExponentForNumber(diff.get(1));
// System.out.println("expWidth: " + expWidth);
// System.out.println("expHeight: " + expHeight);
if (width < 100 || height < 100) {
bboxOffset = 0.00001;
} else if (width < 200 || height < 200) {
@ -81,8 +57,10 @@ public class CoordinatesConverter_Tests {
} else if (width < 1000 || height < 1000) {
bboxOffset = 0.01;
}
System.out.println("applying offset: "+bboxOffset);
bboxOffset = 0.0001;
System.out.println("applying offset: " + bboxOffset);
recalculate = new Recalculate_WGS84_Offset(source_bbox, source_bbox, bboxOffset);
@ -92,11 +70,47 @@ public class CoordinatesConverter_Tests {
System.out.println("bbox with offset: " + recalculate.getBboxWithOffset());
}
private static int getExponentForNumber(double number)
{
String numberAsString = String.valueOf(number);
return numberAsString.substring(numberAsString.indexOf('.') + 1).length() * -1;
private static int getExponentForNumber(double number) {
String numberAsString = String.valueOf(number);
return numberAsString.substring(numberAsString.indexOf('.') + 1).length() * -1;
}
// public static void main(String[] args) {
//
// // double bboxOffset = 0.003;
// String theBBOX = "15.208508,41.442976,15.209360,41.443437";
// double bboxOffset = 0.01; // no offset
// double lowerXR = theBBOX.getLowerLeftX() - bboxOffset;
// double lowerYR = theBBOX.getLowerLeftY() - bboxOffset;
// double upperXR = theBBOX.getUpperRightX() + bboxOffset;
// double upperYR = theBBOX.getUpperRightY() + bboxOffset;
//
// String parmBBOX = BBOX.toBBOXString(new BBOX(lowerXR, lowerYR, upperXR, upperYR, ""),
// bboxFormat);
//
// // Calculating bounding box dimension
// String bbox3857 = WGS84_CoordinatesConverter.toEPSG3857_BBOX(parmBBOX);
// LOG.debug("toEPSG3857_BBOX: " + bbox3857);
// ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBox(bbox3857);
// LOG.debug("BoudingBox width - height: " + diff);
// double width = diff.get(0);
// double height = diff.get(1);
// double ratio = width / height;
// LOG.trace("bbox width: " + width);
// LOG.trace("bbox heigth: " + height);
// LOG.trace("bbox ratio: " + ratio);
//
// // Calculating width/height ratio
// if (ratio > 1) {
// expWidth = expWidth * ratio;
// } else {
// expHeight = expHeight * ratio;
// }
//
// int aspectratioWidth = expWidth.intValue();
// int aspectratioHeight = expHeight.intValue();
//
//}
}

View File

@ -41,7 +41,11 @@ public class Geoportal_Export_To_PDF_Tests {
// private static String PROFILE_ID = "concessioni-estere";
private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "654e07a75bdd5478cca320c0";
private static String[] PROJECT_IDS = { "6388e4f8a1e60e66b7b584ac", "6388d9b3a1e60e66b7b5843a",
"646353c5d7fb4a4633022803", "63f8c481e9d6ac16f394f1e6", "638888fba1e60e66b7b581dd",
"650304487814b87373631242", "6388ea17a1e60e66b7b584dd", "64537208d7fb4a4633022039", "638885fea1e60e66b7b581bd"};
//private static String[] PROJECT_IDS = { "646353c5d7fb4a4633022803" };
// DEV
// 654e07a75bdd5478cca320c0
@ -138,16 +142,22 @@ public class Geoportal_Export_To_PDF_Tests {
USERNAME = "francesco.mangiacrapa";
exporterSource.setAccountname(USERNAME);
exporterSource.setProfileID(PROFILE_ID);
exporterSource.setProjectID(PROJECT_ID);
exporterSource.setProfileTitle("Regime di Concessione");
exporterSource.setScope(CONTEXT);
try {
pdfExporter.createPDFFile(exporterSource);
for (String project_ID : PROJECT_IDS) {
exporterSource.setProjectID(project_ID);
pdfExporter.createPDFFile(exporterSource);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("testExportToPDF terminated");
}
// public static void main(String[] args) {
@ -223,7 +233,6 @@ public class Geoportal_Export_To_PDF_Tests {
}
}
// public static void main(String[] args) {
// gdal.AllRegister();
@ -233,9 +242,6 @@ public class Geoportal_Export_To_PDF_Tests {
//
// }
// Mercator projection
public static ArrayList<Double> convertToPixel(double lng, double lat, double mapWidth, double mapHeight) {
// get x