2

I'm using Openlayers + GeoServer to draw a new point and save it. But there are some errors.

Code as follows:

function onSaveNewPoint() {

      for(var i = 0 ; i < drawedFeaturePointArray.length ; i++){

      var geometry = drawedFeaturePointArray[i].getGeometry().clone();
      geometry.applyTransform(function(flatCoordinates, flatCoordinates2, stride) {
        for (var j = 0; j < flatCoordinates.length; j += stride) {
          var y = flatCoordinates[j];
          var x = flatCoordinates[j + 1];
          flatCoordinates[j] = x;
          flatCoordinates[j + 1] = y;
        }
      });
      var newFeature = new ol.Feature();
      newFeature.setId('cities.2406.new.' + newPointId);
      newFeature.setGeometryName('the_geom');
      newFeature.set('CITY_NAME', newFeature.getId());
      newFeature.set('GMI_ADMIN', newFeature.getId());
      newFeature.set('ADMIN_NAME', 0);
      newFeature.set('FIPS_CNTRY', '');
      newFeature.set('CNTRY_NAME', '');
      newFeature.set('STATUS', 'test');
      newFeature.set('POP_RANK', 0);
      newFeature.set('POP_CLASS', '');
      newFeature.set('PORT_ID', 0);
      newFeature.set('LABEL_FLAG', 0);
      newFeature.setGeometry(new ol.geom.Point([geometry.getCoordinates()]));

      addWfsPoint([newFeature]);
      newPointId = newPointId + 1;
      setTimeout(function(){
        console.log('next Feature');
      },3000);
    }      
  }

function addWfsPoint(features) {
      var WFSTSerializer = new ol.format.WFS();
      var featObject = WFSTSerializer.writeTransaction(features,
        null, null, {
          featureType: 'WorldCities',
          featureNS: 'http://geoserver.org/WorldCities',
          srsName: 'EPSG:4326'
        });
      var serializer = new XMLSerializer();
      var featString = serializer.serializeToString(featObject).replace('undefined','');;

      var request = new XMLHttpRequest();
      request.open('POST', 'http://localhost:8080/geoserver/wfs?service=wfs');
      request.setRequestHeader('Content-Type', 'text/xml');
      request.send(featString);
    }



Errors as follows:

<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://localhost:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>
Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@52de3d55
</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

with browser response as follows:

<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://localhost:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
  <ows:Exception exceptionCode="NoApplicableCode">
    <ows:ExceptionText>java.lang.RuntimeException: Parsing failed for pos: java.lang.RuntimeException: Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
Parsing failed for pos: java.lang.RuntimeException: Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
For input string: "40.73628139583304,-74.00918689125533"</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

and the XML being posted by the browser:

<?xml version="1.0" encoding="utf-8"?>
<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
  <Insert>
    <WorldCities xmlns="http://geoserver.org/WorldCities" fid="cities.2406.new.1">
      <the_geom>
        <Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
          <pos  srsDimension="2">40.73698364739682,-74.00934294690373</pos>
        </Point>
      </the_geom>
      <CITY_NAME>cities.2406.new.1</CITY_NAME>
      <GMI_ADMIN>cities.2406.new.1</GMI_ADMIN>
      <ADMIN_NAME>0</ADMIN_NAME>
      <FIPS_CNTRY/>
      <CNTRY_NAME/>
      <STATUS>test</STATUS>
      <POP_RANK>0</POP_RANK>
      <POP_CLASS/>
      <PORT_ID>0</PORT_ID>
      <LABEL_FLAG>0</LABEL_FLAG>
    </WorldCities>
  </Insert>
</Transaction>



I've searched online, but still don't know how to resolve this problem. I hope someone here can help me out.

3
  • 1
    Please add the XML being posted by the browser in the description, not everybody is a client developer here. – Andrea Aime Sep 17 '18 at 8:29
  • 1
    @AndreaAime hello AndreaAime,thanks for comment.I've edited the question and added the XML. :) – jerry Sep 17 '18 at 8:37
  • hi. good first question IMO; I reworked the title; removed the error qualifier and gave it a more appealing wording (albeit duplicating the tags....). if you think that is unfitting, you can always roll-back or rework it again. – geozelot Sep 17 '18 at 9:19
1

The request is lacking all namespaces besides the WFS one, you'll need to add namespace and prefix for the WorldCities feature and attributes, as well as the GML namespaces for the GML elements in it. Use a GeoServer WFS 1.1 response as guidance.

2
  • thank you very much.I think i found the solution. :) – jerry Sep 17 '18 at 13:53
  • @jerry, if this answer helped you, please accept it. Otherwise, if you have found another solution, please add another answer and accept it so others can benefit from your solution. – Fezter Oct 11 '18 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.