1

When I add a MultiPolygon geometry which has been draw by an user on my map, the geometry not displaying at the place where i draw it. It display at a different place.

I send the geometry to my api which his goal is to add the geometry in my postgre Databse. So in my API :

var geom = req.body.geom
  var geom2 = "ST_GeomFromText('" + geom + "',2154)"
  pool.query( 'INSERT INTO potentiel_foncier_ccry (nature, geom, nbr_lgmt) VALUES ('+ mysql.escape(nature)+','+geom2+','+mysql.escape(logement)+')'

In my function which display my data :

foncier2.getSource().addFeatures(foncier2.getSource().getFormat().readFeatures(
myGeoJSON, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}));
foncier2.getSource().refresh();
foncier2.getSource().changed();
map.getView().fit(foncier2.getSource().getExtent());
}

The problem comes from the Projection ? In my Database I am force to store my geometry in EPSG:2154.

Example I draw here :

I draw here

After add the geometry in the database when i want to display it, It display on the sea :

![enter image description here

Ps : I work with OpenLayer 5.3.0.

  • Looks like you are using a different projection when saving the geometry `"ST_GeomFromText('" + geom + "',2154)"` and then `dataProjection: 'EPSG:4326',` – Juan Carlos Oropeza Apr 03 '19 at 14:22
  • Yes because when I put 4326 instead of 2154 it tells me 'Geometry SRID (4326) does not match column SRID (2154)' – Alain Bouquety Apr 03 '19 at 14:31
  • Does ST_GeomFromText actually transform the geometry? Should you be using ST_Transform? – Mike Apr 03 '19 at 14:32
  • Thanks you very much Mike , The solution was to use ST_Transform !!! – Alain Bouquety Apr 03 '19 at 14:49
  • You already transform the geometry when sending it from openlayers, so you could also just transform it to 2154 there ( { dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857' } But you would need to install the projection plugin (http://proj4js.org/). – Astrogat Apr 04 '19 at 14:41
  • Thanks you i will add that too – Alain Bouquety Apr 05 '19 at 08:13

0 Answers0