Skip to content

Commit

Permalink
Force le SRID en int/Integer
Browse files Browse the repository at this point in the history
La récupération JS du SRID était automatiquement interprétée en int
Problème : un switch basé sur une string n'était pas pris en compte
Correction du problème et dans le doute on force le cast côté JS

La valeur d'un code dans le référentiel EPSG étant obligatoirement un
entier unique entre 1024 et 32766, on bascule tout en int/Integer pour
éviter la confusion (les méthodes JTS et PostGIS utilisent des entiers
lorsque le SRID est utilisé)

Issue #241269

Change-Id: Ia9a211671d11b938ac836d30beafe0ebf3f54414
  • Loading branch information
tdegivry committed Jan 24, 2025
1 parent 0a3dfec commit ff93fef
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 38 deletions.
4 changes: 2 additions & 2 deletions client-ng/src/components/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ export default {
this.proj = this.map.getView().getProjection()
this.epsg = 'EPSG:' + this.srid
switch(this.srid) {
case "2154":
case 2154:
proj4.defs(this.epsg, '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs')
break;
case "2972":
case 2972:
proj4.defs(this.epsg, '+proj=utm +zone=22 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs')
break;
}
Expand Down
4 changes: 2 additions & 2 deletions client-ng/src/components/OlMap/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export default {
this.proj = this.map.getView().getProjection()
this.epsg = 'EPSG:' + this.srid;
switch(this.srid) {
case "2154":
case 2154:
proj4.defs(this.epsg, '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs')
break;
case "2972":
case 2972:
proj4.defs(this.epsg, '+proj=utm +zone=22 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs')
break;
}
Expand Down
6 changes: 3 additions & 3 deletions client-ng/src/components/utils/FunctionsUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from "axios";


export async function getSrid() {
let srid;
await axios.get('/remocra/parametre/srid').then(response => srid = response.data );
return srid;
}
let res = parseInt(srid);
return !isNaN(res) ? res : null;
}
4 changes: 2 additions & 2 deletions remocra/src/main/java/fr/sdis83/remocra/GlobalConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/** Classe permettant de définir des constantes globales */
public class GlobalConstants {
public static final String SRID_4326 = "4326";
public static final String SRID_3857 = "3857";
public static final int SRID_4326 = 4326;
public static final int SRID_3857 = 3857;
public static final String LDAP_PASSWORD = "LDAP";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private Double getLatOrLong(int param) {
GeometryUtil.transformCordinate(
p.getX(),
p.getY(),
parametreDataProvider.get().getSridString(),
parametreDataProvider.get().getSridInt(),
GlobalConstants.SRID_4326);

return BigDecimal.valueOf(coordonneConvert[param])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public PlusProchePei closestPei(String json) throws CRSException, IllegalCoordin

Integer distanceMaxParcours = parametreProvider.get().getDeciDistanceMaxParcours();

String srid = parametreProvider.get().getSridString();
int srid = parametreProvider.get().getSridInt();
Geometry geom = GeometryUtil.createPoint(longitude, latitude, srid);
String query =
"SELECT pei, chemin, dist FROM couverture_hydraulique.plus_proche_pei(ST_GeomFromText('"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public String getExtentById(Long id) {
"SELECT St_AsEwkt(St_transform(St_SetSrid(CAST(St_Extent(geometrie) AS Geometry),"
+ parametreProvider.get().getSridInt()
+ "),"
+ Integer.parseInt(GlobalConstants.SRID_3857)
+ GlobalConstants.SRID_3857
+ ")) AS geometrie FROM remocra.commune WHERE id IN(SELECT commune FROM remocra.crise_commune WHERE crise ="
+ id
+ ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public long addPeiProjet(String json) throws CRSException, IllegalCoordinateExce
GeometryUtil.createPoint(
longitude,
latitude,
parametreProvider.get().getSridString(),
parametreProvider.get().getSridString());
parametreProvider.get().getSridInt(),
parametreProvider.get().getSridInt());

long idPeiProjet =
context
Expand Down Expand Up @@ -234,7 +234,7 @@ public void deletePeiProjet(String json) {
.execute();
}

public void updateGeometrie(String json, String srid)
public void updateGeometrie(String json, int srid)
throws CRSException, IllegalCoordinateException {
HashMap<String, Object> obj = new JSONDeserializer<HashMap<String, Object>>().deserialize(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public String getEtenduEtude(Long idEtude) {
+ ") as Geometry), "
+ parametreProvider.get().getSridInt()
+ "), "
+ Integer.parseInt(GlobalConstants.SRID_3857)
+ GlobalConstants.SRID_3857
+ "))")
.as("geometrie"))
.from(ETUDE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void addHydrantAspirationFromFiche(Long id, String data)
longitude,
latitude,
GlobalConstants.SRID_4326,
parametreProvider.get().getSridString());
parametreProvider.get().getSridInt());
int lon =
BigDecimal.valueOf(coordonneConvert[0]).setScale(0, RoundingMode.HALF_UP).intValue();
int lat =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ public int getDistanceFromCoordonnees(long idHydrant, double latitude, double lo
"SELECT ST_DISTANCE(ST_transform(ST_SetSRID(ST_MakePoint({0}, {1}),{2}), {3}), h.geometrie) "
+ "FROM remocra.hydrant h "
+ "WHERE h.id = {4};",
longitude, latitude, Integer.parseInt(GlobalConstants.SRID_4326), srid, idHydrant)
longitude, latitude, GlobalConstants.SRID_4326, srid, idHydrant)
.fetchOneInto(int.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void updateMany(String json) throws Exception {
longitude,
latitude,
GlobalConstants.SRID_4326,
parametreProvider.get().getSridString());
parametreProvider.get().getSridInt());
longitude =
BigDecimal.valueOf(coordonneConvert[0]).setScale(0, RoundingMode.HALF_UP).intValue();
latitude =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public Point coordonneesToPoint(String json)
} else {
// Si les données sont en WSG84 en degrés sexagésiamaux, on les convertit d'abord en degrés
// décimaux
if (srid == Integer.parseInt(GlobalConstants.SRID_4326) && !degres) {
if (srid == GlobalConstants.SRID_4326 && !degres) {
longitude =
GeometryUtil.convertDegresSexagesimauxToDecimaux(items.get("longitude").toString());
latitude =
Expand All @@ -542,8 +542,8 @@ public Point coordonneesToPoint(String json)
GeometryUtil.transformCordinate(
longitude,
latitude,
items.get("systeme").toString(),
parametreProvider.get().getSridString());
Integer.parseInt(items.get("systeme").toString()),
parametreProvider.get().getSridInt());
longitude =
BigDecimal.valueOf(coordonneConvert[0]).setScale(0, RoundingMode.HALF_UP).intValue();
latitude =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public void fillHydrant(fr.sdis83.remocra.xml.Hydrant hydrantXML, Hydrant hydran
GeometryUtil.transformCordinate(
hydrant.getGeometrie().getX(),
hydrant.getGeometrie().getY(),
parametreProvider.get().getSridString(),
parametreProvider.get().getSridInt(),
GlobalConstants.SRID_4326);
hydrantXML.setCoordonnee(new Coordonnee(coordonneConvert[0], coordonneConvert[1]));
}
Expand Down Expand Up @@ -851,7 +851,7 @@ public void deSerializeHydrants(String xml, Integer version)
coordonnee.getLongitude(),
coordonnee.getLatitude(),
GlobalConstants.SRID_4326,
parametreProvider.get().getSridString());
parametreProvider.get().getSridInt());
hydrantPena.setGeometrie(point);
hydrantPena.setDateGps(null);
}
Expand Down Expand Up @@ -883,7 +883,7 @@ public void deSerializeHydrants(String xml, Integer version)
coordonnee.getLongitude(),
coordonnee.getLatitude(),
GlobalConstants.SRID_4326,
parametreProvider.get().getSridString());
parametreProvider.get().getSridInt());
hydrantPibi.setGeometrie(point);
hydrantPibi.setDateGps(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public void addVisiteFromImportCtp(String visitesData)
longitude,
latitude,
GlobalConstants.SRID_4326,
parametreDataProvider.get().getSridString());
parametreDataProvider.get().getSridInt());
Point p = geometryFactory.createPoint(new Coordinate(coordonnees[0], coordonnees[1]));
hydrantRepository.updateGeometrie(idHydrant, p);
}
Expand Down
12 changes: 5 additions & 7 deletions remocra/src/main/java/fr/sdis83/remocra/util/GeometryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,21 @@ public static CRSFactory getCRSFactory() {
return cRSFactory;
}

public static Point createPoint(double longitude, double latitude, String proj)
public static Point createPoint(double longitude, double latitude, int proj)
throws CRSException, IllegalCoordinateException {
GeometryFactory geometryFactory =
new GeometryFactory(new PrecisionModel(), Integer.parseInt(proj));
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), proj);
return geometryFactory.createPoint(new Coordinate(longitude, latitude));
}

public static Point createPoint(double longitude, double latitude, String projFrom, String projTo)
public static Point createPoint(double longitude, double latitude, int projFrom, int projTo)
throws CRSException, IllegalCoordinateException {
double[] coord = transformCordinate(longitude, latitude, projFrom, projTo);
GeometryFactory geometryFactory =
new GeometryFactory(new PrecisionModel(), Integer.parseInt(projTo));
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), projTo);
return geometryFactory.createPoint(new Coordinate(coord[0], coord[1]));
}

public static double[] transformCordinate(
double longitude, double latitude, String projFrom, String projTo)
double longitude, double latitude, int projFrom, int projTo)
throws CRSException, IllegalCoordinateException {
CoordinateReferenceSystem fromCoordRefSys = getCRSFactory().getCRS("EPSG:" + projFrom);
CoordinateReferenceSystem toCoordRefSys = getCRSFactory().getCRS("EPSG:" + projTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public ResponseEntity<String> updateGeometrie(MultipartHttpServletRequest reques
try {
String json = request.getParameter("peiProjet");

etudeHydrantProjetRepository.updateGeometrie(
json, String.valueOf(parametreProvider.get().getSridInt()));
etudeHydrantProjetRepository.updateGeometrie(json, parametreProvider.get().getSridInt());
return new SuccessErrorExtSerializer(true, "Le pei projet a bien été déplacé.").serialize();
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ public ResponseEntity<java.lang.String> transformCoordonnees(
} else {
double[] coordonneConvert =
GeometryUtil.transformCordinate(
longitude, latitude, parametreProvider.get().getSridString(), srid.toString());
longitude, latitude, parametreProvider.get().getSridInt(), srid);

// Si on a choisi le système WGS84 et qu'on ne souhaite pas l'exprimer en degrés décimaux,
// on le convertit en degrés minutes secondes
if (srid == Integer.parseInt(GlobalConstants.SRID_4326) && !degres) {
if (srid == GlobalConstants.SRID_4326 && !degres) {
String longitudeConvert =
GeometryUtil.convertDegresDecimauxToSexagesimaux(coordonneConvert[0]);
String latitudeConvert =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public String show(HttpServletRequest request, Model model) {

model.addAttribute("show_historique", parametreProvider.get().getHydrantNombreHistorique() > 0);

model.addAttribute("srid", parametreProvider.get().getValeurString(GlobalConstants.CLE_SRID));
model.addAttribute("srid", parametreProvider.get().getSridInt());

model.addAttribute(
"buffer_carte", parametreProvider.get().getValeur(GlobalConstants.CLE_BUFFER_CARTE));
Expand Down

0 comments on commit ff93fef

Please sign in to comment.