[GIS] Issue with a point insertion into a Geoserver points layer. WFS-T

geojsongeoserveropenlayerswfswfs-t

What is the best way to insert a feature from the client side into an existing GeoServer layer? Maybe using an AJAX call and JSONP? Or OpenLayers (i can't figure out how to have the proxy working)?

If someone have an example, I'll be very grateful

UPDATE

Actually what I'm trying is:

1- Build WFS-T formatted string in this way (reduced version):

<wfs:Transaction
 <wfs:Insert>
  <sde:uruguayos>
   <sde:the_geom>
     <gml:Point srsDimension="1" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
       <gml:coordinates decimal="." cs="," ts=" ">-33.7291,-56.3353820</gml:coordinates>
     </gml:Point>
   </sde:the_geom>
  <sde:Name>Uruguayo Nuevo</sde:Name>
 </sde:uruguayos>
</wfs:Insert>

After that, i'm sending a POST with the data above via ajax to GeoServer and now i fall out into a cross-domain-issue (and make sense).

jQuery.ajax({
  async: false,
  dataType: 'text/xml',
  type: "POST",
  url: wfs,
  data: postData,
  //TODO: Error handling
  success: function(xml) {  
    //TODO: User feedback
    alert("Ready...");
  },
  failure: function (xml) {
          alert("Something went wrong in the request");
  }
});

UPDATE 2

I could solve the Cross domain issue. And now I'm with a strange problem making the insertion over my PostGIS Layer (through GeoServer).

As I said, I have this xml string:

var wfs = "http://"+ip+":"+port+"/geoserver/ows?service=wfs&request=Transaction";
var wfsEncoded = encodeURIComponent(wfs);

// INSERT point

var postData = 
    '<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"     '+
  'xmlns:sde="http://geoserver.sf.net" '+
  'xmlns:gml="http://www.opengis.net/gml" '+
  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
  'xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd '+'http://www.openplans.org/topp '+ wfsEncoded +'/DescribeFeatureType?typename=sde:uruguayos">'+
  '<wfs:Insert><sde:uruguayos><sde:geom> '+
        '<gml:Point srsDimension="1" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857"> '+
         '<gml:coordinates decimal="." cs="," ts=" ">-33.7291,-56.3353820</gml:coordinates> '+ 
         '</gml:Point> </sde:geom> <sde:Name>Uruguayo Nuevo</sde:Name> </sde:uruguayos>          </wfs:Insert> '+
    '</wfs:Transaction>';

I make two tries with a different wfs var (url in the code)

var wfs = "http://"+ip+":"+port+"/geoserver/ows?service=wfs&request=Transaction";

And

var wfs = "http://"+ip+":"+port+"/geoserver/wfs";

The first one got a response that says:

 <ows:ExceptionReport 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://192.168.38.229: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@1d08ec4</ows:ExceptionText>
  </ows:Exception>
 </ows:ExceptionReport>

And the second response from Geoserver is like that:

 <ows:ExceptionReport 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://192.168.38.229:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
   <ows:Exception exceptionCode="NoApplicableCode">
     <ows:ExceptionText>Could not find request reader (either kvp or xml) for: net.opengis.wfs20.TransactionType</ows:ExceptionText>
   </ows:Exception>
 </ows:ExceptionReport>

The URL encoding tip was taken from Data request to GeoServer: "Could not determine geoserver request from http request GET /geoserver/ows?service=WFS HTTP/1.1"

Best Answer

I might advise a powerful client GIS as UDIG (http://www.refractions.net/products/geoserver/)

Related Question