Home > openlayers > Oracle / GeoServer / WFS-T / Openlayers many polygons as one feature

Oracle / GeoServer / WFS-T / Openlayers many polygons as one feature

February 26Hits:1
Advertisement

Newbie question regarding Oracle / GeoServer / WFS-T / Openlayers. I am creating a table that will hold geometry features a user creates/updates. My question is, I would like to have just one record in the table per customer (customerId). Can I create many polygons/points/lines as one feature in OpenLayers and have that go to GeoServer/WFS-T as one feature that then gets written all in one record in the Oracle Table? Currently I have it all running but it is creating one record for each feature.

One more thing to note, Oracle does allow this by setting the SDO_GTYPE (geometry type) as a MULTIPOLYGON (2007). The questions is how to create multiple features as one record in OpenLayers/ WFS-T / GeoServer. Is there a setting in the Editable Layer I am missing? Thanks.

Here is my editable layer:

var saveStrategy = new OpenLayers.Strategy.Save();          customers = new OpenLayers.Layer.Vector("Customers", {             strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],             projection: new OpenLayers.Projection("EPSG:2236"),             protocol: new OpenLayers.Protocol.WFS({                 version: "1.1.0",                 srsName: "EPSG:2236",                 url: "http://server01:8085/geoserver/sf/wfs",                 featurePrefix: "sf",                 featureType: "customers",                 featureNS: "http://a.org/layers01",                 geometryName: "GEOMETRY"             })         }); 

This is the feature added method:

function FeatureAdded(object)         {              var added_feature = object.feature;             added_feature.state = OpenLayers.State.INSERT;              // Setup Customer Id for inserting to one record             // NOTE: This is not working, it just creates multiple records             //       with the next id number (seed)             added_feature.attributes.customerId = 123456;              saveStrategy.save();          } 

When I set the strategy to OpenLayers.Strategy.BBOX(), I get multiple records created in the table. (I am looking to create just one MultiPolygon record in the table.) When I set the strategy to OpenLayers.Strategy.Fixed(), I get no client error (fail method for the strategy does not fire), no GeoServer log error and no records written to the table.

Update # 1

As requested, here is a sample post request. In this case I created two polygons which I only wanted to be one record, but it created two records in the table:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs  http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"> <wfs:Insert>   <feature:CUSTOMERS xmlns:feature="http://a.org/layers01">     <feature:GEOMETRY>       <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:2236">         <gml:surfaceMember>           <gml:Polygon>             <gml:exterior>               <gml:LinearRing>                 <gml:posList>701479.552253 437319.29214775 799997.3100655 437319.29214775 799997.3100655                              436384.8351165 701092.880378 436223.72183525 700899.5444405 436771.5069915                              701479.552253 437319.29214775                 </gml:posList>               </gml:LinearRing>             </gml:exterior>           </gml:Polygon>         </gml:surfaceMember>       </gml:MultiSurface>     </feature:GEOMETRY>     <feature:CUSTOMERID>123456</feature:CUSTOMERID>   </feature:CUSTOMERS> </wfs:Insert> <wfs:Insert>   <feature:CUSTOMERS xmlns:feature="http://a.org/layers01">     <feature:GEOMETRY>       <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:2236">         <gml:surfaceMember>           <gml:Polygon>             <gml:exterior>               <gml:LinearRing>                 <gml:posList>701608.442878 435611.4913665 700738.43115925 434805.92496025 701253.99365925                              433968.13589775 702059.5600655 434258.139804 701608.442878 435611.4913665                 </gml:posList>               </gml:LinearRing>             </gml:exterior>           </gml:Polygon>         </gml:surfaceMember>       </gml:MultiSurface>     </feature:GEOMETRY>     <feature:CUSTOMERID>123456</feature:CUSTOMERID>   </feature:CUSTOMERS> </wfs:Insert> </wfs:Transaction> 

Update # 2

I tried removing all features and replacing them as one mpolygon:

// Add Polygons to a MultiPolygon              function cmd_Poly_add()             {                  var features = customers.features;                  var polygons = [];                 var f = null;                  for (f in features)                 {                     polygons.push(features[f].geometry);                 }                  var myCombinedFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.MultiPolygon(polygons));                 myCombinedFeature.state = OpenLayers.State.INSERT;                 customers.removeFeatures(features);                 customers.addFeatures([myCombinedFeature]);                 customers.redraw();              }    function FeatureAdded(object) {  cmd_Poly_add()  } 

I then checked the wfs transaction being sent but when I perform the above, the data is getting removed from the body of the wfs:insert.

The original node goes to this level:

 <wfs:Insert>   <feature:CUSTOMERS xmlns:feature="http://a.org/layers01">     <feature:GEOMETRY>       <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:2236">         <gml:surfaceMember>           <gml:Polygon>             <gml:exterior>               <gml:LinearRing>                 <gml:posList> 

Once I create the new polygon with the line:

customers.addFeatures([myCombinedFeature]);

Everything is gone and only creates a transaction to this level:

<wfs:Insert>   <feature:CUSTOMERS xmlns:feature="http://a.org/layers01">     <feature:GEOMETRY>       <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:2236"> 

And I can see it going into the loop and adding the features:

... for (f in features) { polygons.push(features[f].geometry); } ...

To the multipolygon but the transaction is empty as shown above.

Update #3

Update #3 Contains the changes suggested by ahocevar below to move the call to cmd_Poly_add to the save method. This is the error coming back from GeoServer now:

Error performing insert: null 

The above error actually makes sense. Since the mpolygon is not being sent back to GeoServer with spatial data (see # 5 below).

To recap what I am currently trying now, here are the details:

  1. I am only calling cmd_Poly_add (the method to combine the polygons into one mpolygon) one time. As recommend by ahocevar below, the place I am calling cmd_Poly_add now is in the save method which is called only once instead of placing it in the FeatureAdded method which was called every time a new feature is added:

    // Save var save = new OpenLayers.Control.Button({ title: "Save Changes", trigger: function () { if (edit.feature) { edit.selectControl.unselectAll(); }

                    cmd_Poly_add();                  saveStrategy.save();             },             displayClass: "olControlSaveFeatures"         }); 
    
  2. In the cmd_Poly_add, I am using .features method instead of .selectedFeatures method to make sure all features are selected from the layer. (If I use .selectedFeatures, none of the newly drawn polygons are selected):

var features = customers.features;

  1. Also, the customerId is set only once for the mpolygon. (It is no longer set in the FeatureAdded method for every feature):

myCombinedFeature.attributes.customerId = 123456;

Here is the revised method:

// add Polygons to a MultiPolygon              function cmd_Poly_add()             {                  var features = customers.features;                 //var features = wfs_polygon.selectedFeatures;                  var polygons = [];                 var f = null;                  for (f in features) {                     polygons.push(features[f].geometry);                 }                  var myCombinedFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.MultiPolygon(polygons));                  myCombinedFeature.state = OpenLayers.State.INSERT;                  myCombinedFeature.attributes.customerId = 123456;                  customers.removeFeatures(features);                 customers.addFeatures([myCombinedFeature]);                 customers.redraw();              } 
  1. As noted above, the FeatureAdded is empty now: (Since we are setting the attributes in the cmd_Poly_add method above only once for the newly created mpolygon:
    function FeatureAdded(object) { } 
    
  2. Here are the results, as you can see (same as explained in Update #2), it does create just one tree now (one mpolygon) But, the interior nodes containing the spatial information are not being created for the mpolygon:

...

<wfs:Insert> <feature:CUSTOMERS xmlns:feature="http://a.org/layers01"> <feature:GEOMETRY> <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:2236"/> </feature:GEOMETRY> <feature:CUSTOMERID>123456</feature:CUSTOMERID> </feature:CUSTOMERS> </wfs:Insert> 

...

Update # 4

I am now trying to focus on understanding why the multipolygon is missing the spatial data. That is the main problem. (See section 5 above from update #3)

Inside the cmd_Poly_add function is where the problem must be. The first step is to get all the features that where drawn:

var features = customers.features; 

Then "just" the geometry is pushed to an array:

for (f in features) {                         polygons.push(features[f].geometry);                     } 

Finally a new feature is created called myCombinedFeature which holds the polygon array:

var myCombinedFeature = new OpenLayers.Feature.Vector(new    OpenLayers.Geometry.MultiPolygon(polygons)); 

At that point is where the problem must be. Somehow the spatial data is not going over from the polygons array to the Multipolygon (myCombinedFeature).

One important thing I noticed is the myCombinedFeature object has this property:

myCombinedFeature.geometry.components = [] 

while the features has the spatial data:

features[0].geometry.components = [[POLYGON((7.. 

And finally the polygon features are removed and the Multipolygon is added to the layer as one new feature:

customers.removeFeatures(features); customers.addFeatures([myCombinedFeature]); customers.redraw(); 

Once the save button is clicked on and the save is executed:

// Save                 var save = new OpenLayers.Control.Button({                     title: "Save Changes",                     trigger: function () {                         if (edit.feature) {                             edit.selectControl.unselectAll();                         }                          cmd_Poly_add();                          saveStrategy.save();                     },                     displayClass: "olControlSaveFeatures"                 }); 

The spatial data does not go back to GeoServer and an error is produced. (See section 5 above from update #3)

Update #5

The problem is definitely on how myCombinedFeature is getting built. I did a test line as follows:

Right below this line:

var myCombinedFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.MultiPolygon(polygons)); 

I added this line to override the objects to hold just one point:

 myCombinedFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(701864.0014, 435534.8233)); 

And the feature is succesfully updated in the table! So the problem is definitely in the "polygons" object! Somehow the points are not going from the "polygons" object into the "myCombinedFeature" object.

Answers

I do this by using MultPolygon, as you've mentioned above.

The trick I've used is that after drawing a polygon (when your FeatureAdded function is called) it should add a polygon to a JavaScript object that mirrors the structure of a MultiPolygon. Here's a quick pointer on doing that type of wrapping/unwrapping:

http://osgeo-org.1560.x6.nabble.com/Multipolygon-to-Polygons-td5003436.html

Then, have your Save Strategy send that MultiPolygon. I actually don't use SaveStrategy, but build the save functions myself...

I don't know of a simple setting that does all this for you.

"Newbie question regarding Oracle / GeoServer / WFS-T / Openlayers." ... sounds pretty advanced!

Anyway, what about creating view on top of the source data, the view could be consumed by GeoServer and displayed? On the way back (transaction), it could be done with Materialized View, see http://docs.oracle.com/cd/B10501_01/server.920/a96567/repmview.htm

I never tried such thing, just an idea, what could work

Related Articles

  • Oracle / GeoServer / WFS-T / Openlayers many polygons as one featureFebruary 26

    Newbie question regarding Oracle / GeoServer / WFS-T / Openlayers. I am creating a table that will hold geometry features a user creates/updates. My question is, I would like to have just one record in the table per customer (customerId). Can I creat

  • How to add GeoServer wfs layer on OpenLayers?

    How to add GeoServer wfs layer on OpenLayers?March 4

    I can't seem to add a WFS layer like this. It works when i copy all this code locally but as soon as i change the values to point to my own layer within my own GeoServer this is the response viewed in firebug: Could not locate {http://www.mydomain.co

  • GeoServer WFS OpenLayers EditingPanel ProblemJune 13

    I'm trying to use OpenLayers to edit features of vector data served from a local geoserver. So far, I'm able to pull WMS and WFS layers using OpenLayers from the same geoserver. But now, I'd like enable editing of features of the vector layers. The r

  • Geoserver WFS Fails to Load in OpenLayers

    Geoserver WFS Fails to Load in OpenLayersMarch 31

    I'm working with Postgis->Geoserver->openlayers on localhost. I followed a Geoserver tutorial to import some nyc sample data into my postgres/postgis database and link it to Geoserver. The layer seems to display correctly in Geoserver using the open

  • Problem saving added point to GeoServer WFS-T via OpenLayers?

    Problem saving added point to GeoServer WFS-T via OpenLayers?August 20

    I want to add a point and then with WFS-T, save this to db. I work with Openlayers and GeoServer. saveStrategy = new OpenLayers.Strategy.Save(); wfs = new OpenLayers.Layer.Vector( "WFS Vectore", { strategies: [new OpenLayers.Strategy.BBOX(), sav

  • Parameters in a SQL View (Geoserver) and WFS Layer (Openlayers): can't get them to work properlyOctober 22

    I'm relatively new to GIS, openlayers, geoserver and javascript in general. I have the following problem: I need to display a choropleth map by coloring the different areas in my map based on a PostGIS DB attribute selected by the user. Initially I i

  • openlayers: reading polygon attributesOctober 2

    I'm quite new to ogc webservices and I need some guidance. I have a shapefile in geoserver lmes.shp (WMS, WCS and WFS are activated), with attribute LME_ID for each polygon of lmes.shp. I need to write a function that will query the layer lmes for a

  • Drupal-Geoserver WFS error September 24

    I am having trouble getting a WFS layer working using Geoserver, OpenLayers and GeoExt. I get the following error: XMLHttpRequest cannot load http://10.0.0.155/geoserver/wfs. Origin http://10.0.0.155:8080 is not allowed by Access-Control-Allow-Origin

  • geoserver wfs insert errorApril 27

    I keep getting an insert error from geoserver when trying to save a point, poly etc etc to my postgis table. any ideas, my code is below var Projection = new OpenLayers.Projection("EPSG:4326"); var map = new OpenLayers.Map("Map", { //p

  • How to convert a String to OpenLayers.Geometry.Polygon using javascript?

    How to convert a String to OpenLayers.Geometry.Polygon using javascript?July 18

    First let me say that I'm using Javascript, jQuery, Java, GeoServer, OpenLayers and PostGIS. Using java class ResultSet I return this String: POLYGON((516000 2135000,515039.264020162 2125245.48389919,512193.976625564 2115865.82838175,507573.480615127

  • Select single feature from multiple types with WFS in OpenLayersDecember 27

    I have a WMS base and from that create a Vector Layer for selections. Then I create 3 Control.GetFeature() controls, each using WFS to select a different feature type upon clicking the map (the 'featureselect' event). Doing it this way, however, I en

  • Modify WFS with OpenLayersJuly 23

    I want to edit object on WFS layer but have one problem. I use OpenLayers.Control.ModifyFeature(myVecLayer) to editing.By the logic i do this. Press button and create WFS layer with chosen object Add OpenLayers.Control.ModifyFeature to map controls a

  • Is it possible to access geoserver wfs layer from localhost:8080 in to web application? June 3

    I want to add a WFS layer. I am trying to get WFS layer from localhost:8080 geoserver. but I am getting eoserver DateLineWrap in Openlayers.js file... --------------Solutions------------- I guess you want to add WMS form Geoserver to your Openlayers

  • QGIS does not update data in Geoserver WFS-TNovember 14

    I am trying to edit a WFS from geoserver (using PostGIS data) within QGIS. This is the request as recorded by Fiddler <Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version=&quo

  • Geoserver WFS-T insert no response. bug?December 1

    I use Geoserver + Openlayers and want to add and save some new Points via WFS-T. I created insert transaction (correct) and sent it, but no response (include errors) was returned. In console was only: 01 dec 17:34:16 INFO [geoserver.wfs] - Request: g

  • GeoTools WFS Query sortBy not working for GeoServer WFSFebruary 17

    I am using GeoTools to query a GeoServer WFS using the following code: Map connectionParameters = new HashMap(); connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", String.format("%s&request=GetCapabilities", wfsUr

  • Using GeoServer WFS to GetFeature by Clicking on it on the mapSeptember 4

    Can someone point me to document of crafting a Geoserver WFS GetFeature request with CQL_Filters? I've already read the GeoServer CQL_Filter Geometric filter section I have a Geoserver WMS set up to return multiple polygon geometries (from a postgres

  • Geoserver WFS-T "Feature type 'Workspace:Layer' is not available" Error on update / deleteDecember 1

    I am using the following code for insert / update (changed from this source: http://wordpress-dbauszus.rhcloud.com/?p=71): var formatWFS = new ol.format.WFS(); // GML Format zur Interaktion mit WFS var formatGML = new ol.format.GML({ featureNS: 'http

  • Allow GeoServer WFS request by featureIDApril 6

    I'm not able to use the featureID parameter in a WFS URL request for my dataset on GeoServer. Example: http://demo.opengeo.org/geoserver/wfs?version=1.1.0&service=wfs&request=GetFeature&typeName=topp:tasmania_roads&maxFeatures=10&featu

  • Releasing GeoServer WFS-T Feature LockMay 24

    For some reason I'm having trouble finding any documentation about releasing feature locks in a GeoServer WFS (or any WFS for that matter). I can easily request a FeatureLock with a request like this http://localhost:8080/geoserver/wfs?service=WFS&ve

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.545 s.