Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting Polygons to PostGIS database #90

Open
jamieodonnell opened this issue Jan 30, 2020 · 1 comment
Open

Inserting Polygons to PostGIS database #90

jamieodonnell opened this issue Jan 30, 2020 · 1 comment
Milestone

Comments

@jamieodonnell
Copy link

jamieodonnell commented Jan 30, 2020

I have a GeoServer installation on top of a PostGIS database. I am trying to set up a leaflet webmap (using Leaflet WFS-T plugin) so that I can insert, update and delete polygon features. I have managed to get this to work fine for Point features but something seems to be going wrong when inserting polygons.

Below is the request payload to GeoServer:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0">
<wfs:Insert><schememapper:geoserver-polygons xmlns:schememapper="schememapper">
<schememapper:geom><gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326" srsDimension="2">
<gml:exterior><gml:LinearRing srsDimension="2"><gml:posList>-1.3735914230346682 52.03958374014823 -1.9696426391601565 50.929466759820585 -3.7992525100708012 51.977294016543425 -1.3735914230346682 52.03958374014823</gml:posList>
</gml:LinearRing></gml:exterior></gml:Polygon></schememapper:geom></schememapper:geoserver-polygons></wfs:Insert></wfs:Transaction>
And this is the response:
<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://35.242.177.142:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="InvalidParameterValue">
<ows:ExceptionText>Error performing insert: java.lang.String cannot be cast to org.locationtech.jts.geom.Geometry</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
When I look at the geometry type in PostGIS it says it is MultiPolygon so I am conscious that the WFST request is only specifying 'polygon'.

Below is my Leaflet code (I am using Leaflet draw to create the polygons):

var wfstPoly = new L.WFST({
    url: 'http:localhost:8080/geoserver/ows',
//typeNS is the workspace in geoserver
    typeNS: 'schememapper',
    typeName: 'geoserver-polygons',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    style: {
      color: 'blue',
      weight: 2
    }
  }).addTo(map)
    .once('load', function () {
      // map.fitBounds(wfstPoly);
    });


// Drawing
var drawControl = new L.Control.Draw({ 
    draw:{circle:false, circlemarker:false, rectangle:false,
          },
    edit:{featureGroup: wfstPoly } });
map.addControl(drawControl);

map.on('draw:created', function (e) {
    var layer = e.layer;
    wfstPoly.addLayer(layer)});

map.on('draw:edited', function (e) {
    var layers = e.layers;
    layers.eachLayer( function (layer) {
        wfstPoly.editLayer(layer);
        });
});

// Save button
L.easyButton('fa-save', function () {
         wfstPoly.save();
     }, 'Save changes').addTo(map);
Furthermore, when I use the console to look at the original features pulled from GeoServer they are GeoJSON but when I look at the newly created features they don't seem to be. They just have an array of coordinates.

EDIT: This may have something to do with GML versions. I.E. Geoserver is expecting the XML of the request to be structured differently.

Aasked on stackexchange here with bounty:
https://gis.stackexchange.com/questions/348819/leaflet-geoserver-wfst-inserting-polygons-to-postgis-database

@kuzkok
Copy link
Member

kuzkok commented Jan 31, 2020

It is known bug of creating simple geometry when it stores in 'Multi' type.
Was fixed there. You should use one of beta versions since v2.0.1-beta.18 and initialize layer with special option forceMulti.

var wfstPoly = new L.WFST({
    url: 'http:localhost:8080/geoserver/ows',
    typeNS: 'schememapper',
    typeName: 'geoserver-polygons',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    forceMulti: true, //<<<<<<<<<<<here for example
    style: {
      color: 'blue',
      weight: 2
    }
  }).addTo(map)
    .once('load', function () {
      // map.fitBounds(wfstPoly);
    });

@kuzkok kuzkok added this to the 2.1 milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants