Skip to content

Commit

Permalink
Update to laste geotools version
Browse files Browse the repository at this point in the history
Correction on datastoire connection, replacement : in _ not needed anymore
Add debug logs to see all available layers name ( to help to see if geo_parcelle not correctly deployed)
Change File to byte[], no need to write on disk anymore (save some times)
  • Loading branch information
pierrejego committed Sep 17, 2021
1 parent d1c387a commit ab45091
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cadastrapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<spring.version>5.3.8</spring.version>
<hibernate-version>6.0.0.Alpha7</hibernate-version>
<hibernate-annotations-version>5.1.2.Final</hibernate-annotations-version>
<geotools.version>24.0</geotools.version>
<geotools.version>25.2</geotools.version>
<pdfbox.version>3.0.0-RC1</pdfbox.version>
<quartz.version>2.3.2</quartz.version>
<springfox.version>2.10.5</springfox.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -58,6 +59,8 @@
import org.opengis.referencing.operation.TransformException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -98,7 +101,7 @@ public class ImageParcelleController extends CadController {
* @return Response with noContent in case of error, png otherwise
*/
@RequestMapping(path = "/getImageBordereau", produces = {MediaType.IMAGE_PNG_VALUE}, method= {RequestMethod.GET})
public ResponseEntity<File> createImageBordereauParcellaire(
public ResponseEntity<byte[]> createImageBordereauParcellaire(
@RequestParam() String parcelle,
@RequestParam(defaultValue = "0", name ="basemapindex", required = false) int baseMapIndex,
@RequestParam(defaultValue = "1446DE", name ="fillcolor", required = false) String styleFillColor,
Expand All @@ -107,7 +110,7 @@ public ResponseEntity<File> createImageBordereauParcellaire(
@RequestParam(defaultValue = "2", name ="strokewidth", required = false) int styleStrokeWidth) {

// Create empty reponse for default value
ResponseEntity<File> response = new ResponseEntity<File>(HttpStatus.NO_CONTENT);
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(HttpStatus.NO_CONTENT);

final int parcelleIdLength = Integer.parseInt(CadastrappPlaceHolder.getProperty("parcelleId.length"));

Expand Down Expand Up @@ -145,15 +148,21 @@ public ResponseEntity<File> createImageBordereauParcellaire(
try {
dataStore = dsf.createDataStore(connectionParameters);

// check all typeName, geo_parcelle are sometimes visibile in geoserver but not here
// redeploy in geoserver is needed
if(logger.isDebugEnabled()){
logger.debug("Datastore name "+ dataStore.getTypeNames());
for (String typeName : dataStore.getTypeNames()) {
logger.debug("Type name : " + typeName);
}
}

SimpleFeatureSource source;

String cadastreWFSLayerNameOri = CadastrappPlaceHolder.getProperty("cadastre.wfs.layer.name");

// remove this if not using gt-wfs-ng anymore
// using ng extension : need to be changed by_
String cadastreWFSLayerName = cadastreWFSLayerNameOri.replaceFirst(":", "_");
String cadastreWFSLayerName = CadastrappPlaceHolder.getProperty("cadastre.wfs.layer.name");
String cadastreLayerIdParcelle = CadastrappPlaceHolder.getProperty("cadastre.layer.idParcelle");

logger.debug("Cadastre WFS LayerName "+ cadastreWFSLayerName);
source = dataStore.getFeatureSource(cadastreWFSLayerName);

// Make sure source have been found before making request filter
Expand Down Expand Up @@ -288,15 +297,14 @@ public ResponseEntity<File> createImageBordereauParcellaire(
if(plotLayerWmsUrl != null && !plotLayerWmsUrl.isEmpty()){
wmsCadastralLayer = createWebMapServer(plotLayerWmsUrl,plotLayerWmsUsername, plotLayerWmsPassword );

cadastreWFSLayerNameOri = CadastrappPlaceHolder.getProperty("parcelle.wms.layer.name");
//TODO see if specific SRS and format are needed
requestCadastralLayer = createAndConfigureMapRequest(wmsCadastralLayer, cadastralLayerFormat, cadastreWFSLayerNameOri, pdfImagePixelSize, cadastreSRS, bounds);
requestCadastralLayer = createAndConfigureMapRequest(wmsCadastralLayer, cadastralLayerFormat, cadastreWFSLayerName, pdfImagePixelSize, cadastreSRS, bounds);
cadastreLayerIdParcelle = CadastrappPlaceHolder.getProperty("parcelle.wms.layer.id");
}

logger.debug("Create feature image from WMS");

StyledLayerDescriptor sld = generateSLD(cadastreWFSLayerNameOri, cadastreLayerIdParcelle, parcelle, styleFillColor, styleFillOpacity, styleStrokeColor, styleStrokeWidth);
StyledLayerDescriptor sld = generateSLD(cadastreWFSLayerName, cadastreLayerIdParcelle, parcelle, styleFillColor, styleFillOpacity, styleStrokeColor, styleStrokeWidth);

SLDTransformer styleTransform = new SLDTransformer();
styleTransform.setEncoding(Charset.forName("UTF-8"));
Expand Down Expand Up @@ -373,14 +381,16 @@ public ResponseEntity<File> createImageBordereauParcellaire(

g2.dispose();

// Get temp folder from properties file
final String tempFolder = CadastrappPlaceHolder.getProperty("tempFolder");

File file = new File(tempFolder + File.separator + "BP-" + parcelle + ".png");
file.deleteOnExit();
ImageIO.write(finalImage, "png", file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(finalImage, "png", baos);
byte[] bytes = baos.toByteArray();

// Create response
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
headers.setContentDispositionFormData("filename", "BP-" + parcelle + ".png");

response = new ResponseEntity<File>(file, HttpStatus.OK);
response = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
} else {
logger.info("No plots corresponding on WFS server");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testCreateImageBordereauParcellaire() {

ImageParcelleController imageParcelleController = new ImageParcelleController();

ResponseEntity<File> response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2);
ResponseEntity<byte[]> response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2);


}
Expand Down

0 comments on commit ab45091

Please sign in to comment.