Add new outputformat geotiff-cog#4166
Open
franklgln wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new cog output format intended to generate Cloud Optimized GeoTIFF (COG) results from MapFish Print, wiring the format into the Spring output-format registry and introducing a dedicated JasperReports-backed GeoTIFF exporter.
Changes:
- Registers new
cogoutput format beans for both standard (JasperReport) and map-export templates. - Introduces
JasperReportGeoTiffOutputFormatto render a Jasper report to an in-memory image and write it as a GeoTIFF-like output via GeoTools.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| core/src/main/resources/mapfish-spring-config-output-formats.xml | Adds cog output format bean registrations for standard and map-export modes. |
| core/src/main/java/org/mapfish/print/output/JasperReportGeoTiffOutputFormat.java | New output format implementation that renders JasperPrint pages to an image and writes a tiled/compressed GeoTIFF to the response. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <bean id="tiffMapOutputFormat" class="org.mapfish.print.output.MapExportOutputFormat" scope="prototype" | ||
| p:fileSuffix="tiff" p:contentType="image/tiff"/> | ||
| <bean id="cogMapOutputFormat" class="org.mapfish.print.output.MapExportOutputFormat" scope="prototype" | ||
| p:fileSuffix="cog" p:contentType="image/cog"/> |
Member
There was a problem hiding this comment.
Comment on lines
+119
to
+144
| Map<String, org.mapfish.print.attribute.map.MapAttribute.MapAttributeValues> maps = | ||
| print.values().find(org.mapfish.print.attribute.map.MapAttribute.MapAttributeValues.class); | ||
|
|
||
| if (maps.isEmpty()) { | ||
| throw new IllegalStateException("No map found in print values"); | ||
| } | ||
|
|
||
| // Get the first map's bounds | ||
| org.mapfish.print.attribute.map.MapAttribute.MapAttributeValues mapValues = | ||
| maps.values().iterator().next(); | ||
| ReferencedEnvelope bbox = | ||
| mapValues | ||
| .getMapBounds() | ||
| .toReferencedEnvelope( | ||
| new java.awt.Rectangle(mapValues.getWidth(), mapValues.getHeight())); | ||
|
|
||
| String srs = mapValues.getProjection(); | ||
| LOGGER.info("Map SRS: {}", srs); | ||
|
|
||
| try { | ||
|
|
||
| bbox.setCoordinateReferenceSystem(CRS.decode(srs)); | ||
|
|
||
| GridCoverageFactory factory = new GridCoverageFactory(); | ||
| GridCoverage2D coverage = factory.create("coverage", image, bbox); | ||
|
|
Comment on lines
+179
to
+183
| } catch (Exception e) { | ||
| LOGGER.error("Error writing GeoTIFF: ", e); | ||
| } | ||
| LOGGER.info("GeoTIFF written successfully"); | ||
| } |
Comment on lines
+149
to
+178
|
|
||
| // getting a format | ||
| final GeoTiffFormat format = new GeoTiffFormat(); | ||
|
|
||
| // getting the write parameters | ||
| final GeoTiffWriteParams wp = new GeoTiffWriteParams(); | ||
|
|
||
| // setting compression to LZW | ||
| wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); | ||
| wp.setCompressionType("LZW"); | ||
| wp.setCompressionQuality(0.75F); | ||
|
|
||
| // setting the tile size | ||
| wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT); | ||
| wp.setTiling(tileWidth, tileHeight); | ||
|
|
||
| // setting the write parameters for this geotiff | ||
| final ParameterValueGroup params = format.getWriteParameters(); | ||
| params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); | ||
|
|
||
| GridCoverageWriter writer = null; | ||
|
|
||
| writer = format.getWriter(tmp); | ||
| writer.write( | ||
| coverage, | ||
| (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); | ||
|
|
||
| Files.copy(tmp.toPath(), outputStream); | ||
| writer.dispose(); | ||
| tmp.delete(); |
Comment on lines
+145
to
+146
| final int tileWidth = 512; // fixeded value | ||
| final int tileHeight = 512; // fixeded value |
Comment on lines
+41
to
+45
| private String fileSuffix; | ||
|
|
||
| @Override | ||
| public String getContentType() { | ||
| return "image/" + this.fileSuffix; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for a new GeoTIFF COG output format. (#3805)
The implementation has been reworked to follow the project’s contribution workflow. The changes are based on the latest codebase, target the master branch, and comply with the pre-commit hooks and formatting rules.
All checks pass locally.