1

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"

  • The best way, would be to use WFS-T to insert an new feature. Can you tell me how you are creating this point, so that I can provide a general workflow on how you can do this? – Devdatta Tengshe Mar 10 '14 at 2:40
  • @DevdattaTengshe...I have to edit the question, now the problem is another. I found by researching how to make a WFS-T (i think properly) insertion. Although the question change, i'm glad to know if i'm in the right way. – halbano Mar 10 '14 at 3:30
  • I think you are very close to solving the issue. You just need to get your proxy working. please have a look at this answer on why it is needed: gis.stackexchange.com/questions/27729/… What WebServer are you using for hosting your Javascript Application? – Devdatta Tengshe Mar 10 '14 at 3:44
  • The application is running over Rails. Ruby on Rails. I just now could resolve the whole issue using software.dzhuvinov.com/cors-filter-installation.html Thanks for your support @DevdattaTengshe! – halbano Mar 10 '14 at 5:01
  • @DevdattaTengshe, some bad news. You have any clue? – halbano Mar 11 '14 at 6:26
-4

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

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.