Я создал базу данных postgres с расширением postgis и таблицу с этой командой:
create table lgeognad33 (ID serial primary key, geom geometry(POLYGON,3857) not null );
, затем создал рабочее пространство и хранилище данных postgis и опубликовал эту таблицу как слой в геосервере ... этот слой будетиспользоваться клиентом openlayers в качестве запросов 'WFS' ... код клиента:
var formatWFS = new WFS();
var formatGML = new GML({
featureNS: 'https://data.drawns.org/',
featureType: 'lgeognad33',
srsName: 'EPSG:3857'
});
var sourceWFS = new VectorSource({
loader: function (extent) {
$.ajax('http://localhost:8080/geoserver/SDWS/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'lgeognad33',
srsname: 'EPSG:3857',
// bbox: extent.join(',') + ',EPSG:3857'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response));
});
},
//strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ()),
strategy: extent,
projection: 'EPSG:3857'
});
var layerWFS = new VectorLayer({
source: sourceWFS
});
var map = new Map({
target: 'map',
controls: [],
layers: [
new TileLayer({
source: new OSM()
}), layerWFS
],
view: new View({
// center: fromLonLat([-1.7, 53.2]),
center: [4086950.39, 4127574.58],
zoom: 6
})
});
var transactWFS = function (p, f) {
let node;
switch (p) {
case 'insert':
node = formatWFS.writeTransaction([f], null, null, formatGML);
break;
}
var s = new XMLSerializer();
var str = s.serializeToString(node);
$.ajax('http://localhost:8080/geoserver/SDWS/lgeognad33/wfs', {
service: 'WFS',
type: 'POST',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: str,
}).done();
}
var interaction;
$('#drawPoly').on('click', function (event) {
interaction = new Draw({
type: 'Polygon',
source: layerWFS.getSource()
});
map.addInteraction(interaction);
interaction.on('drawend', function (e) {
transactWFS('insert', e.feature);
});
});
Я ожидаю, что данные, вставленные в БД, будут в формате epsg: 3857, но результатлюбого вставленного многоугольника - 0 0 0 1 1 1 1 0 0 0 ... я не знаю, преобразовывает ли геосервер данные или перепроектирует их (не нашел никакой подсказки, почему это происходит) ...
полезная нагрузка запроса, отправленная от клиента:
<Transaction xmlns="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"><Insert><lgeognad33 xmlns="https://data.test.org/"><geometry><Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"><exterior><LinearRing srsName="EPSG:3857"><posList srsDimension="2">4039544.0708149946 4071341.874581627 4144721.421735397 4034652.1010047426 4012638.236858613 3995516.342522732 4039544.0708149946 4071341.874581627</posList></LinearRing></exterior></Polygon></geometry></lgeognad33></Insert></Transaction>
Примечание: Собственная SRS и Объявленная SRS в геосервере: epsg: 3857
Примечание: Это фотография таблицы, единственная другая строка - это строка, которую я вставил моей рукой, и она правильно отображается на карте, все остальные строки отличаютсяполигоны, предоставленные клиентом изображение базы данных
Примечание: запрос на транзакцию:
Request: transaction
service = WFS
version = 1.1.0
baseURL = http://localhost:8080/geoserver/
group[0] = wfs:insert=net.opengis.wfs.impl.InsertElementTypeImpl@fa0073 (feature: [SimpleFeatureImpl:lgeognad33=[SimpleFeatureImpl.Attribute: geom<geom id=fid--5772524c_1681ace82ae_-7ff7>=POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))]], handle: null, idgen: <unset>, srsName: null)
insert[0]:
feature[0] = SimpleFeatureImpl:lgeognad33=[SimpleFeatureImpl.Attribute: geom<geom id=fid--5772524c_1681ace82ae_-7ff7>=POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))]
idgen = GenerateNew
inputFormat = text/xml; subtype=gml/3.1.1
releaseAction = ALL