lundi 2 mars 2015

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


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://ift.tt/1m4nTUG" service="WFS" version="1.1.0"
xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1m4nTUG
http://ift.tt/1s4HSSQ">
<wfs:Insert>
<feature:CUSTOMERS xmlns:feature="http://a.org/layers01">
<feature:GEOMETRY>
<gml:MultiSurface xmlns:gml="http://ift.tt/WaETtx" 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:LAST_MODIFIED_DATE>2015-02-26</feature:LAST_MODIFIED_DATE>
</feature:CUSTOMERS>
</wfs:Insert>
<wfs:Insert>
<feature:CUSTOMERS xmlns:feature="http://a.org/layers01">
<feature:GEOMETRY>
<gml:MultiSurface xmlns:gml="http://ift.tt/WaETtx" 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:LAST_MODIFIED_DATE>2015-02-26</feature:LAST_MODIFIED_DATE>
</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://ift.tt/WaETtx" 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://ift.tt/WaETtx" 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.





Aucun commentaire:

Enregistrer un commentaire