OL3 多边形 WFS 特征搜索 - 轴方向未定义
OL3 polygon WFS feature search - axis orientation undefined
我有一个允许用户在地图上绘制多边形的应用程序,然后使用 JSTS 库将多边形与 WFS 图层相交并读取与用户的多边形相交的要素。
用户在地图上绘制 select 多边形后发生错误,返回错误:
'无法读取未定义的 属性 'getAxisOrientation''
这似乎是一个与投影相关的问题(我正在使用 EPSG:27700 投影)。
绘制用户多边形时的代码如下 - 是否需要在 WFS 读取要素方法中包含投影?
draw.on('drawend',function(e){
var extent = e.feature.getGeometry().getExtent();
var geomA = e.feature.getGeometry();
myDrawSource.clear();
mySelectionsSource.clear();
$.ajax('../../geoserver/wfs', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'planning:flood_zone_2',
srsname: 'EPSG:27700',
bbox: extent.join(',') + ',EPSG:27700'
}
}).done(function(resp){
var formatWFS = new ol.format.WFS();
var featuresInExtent = formatWFS.readFeatures(resp);
var featuresOnDrawPoly = new Array();
for (var i=0;i<featuresInExtent.length;i++){
var geomB = featuresInExtent[i].getGeometry();
if (polyIntersectsPoly(geomA,geomB)===true){
featuresOnDrawPoly.push(featuresInExtent[i])
}
}
mySelectionsSource.addFeatures(featuresOnDrawPoly);
//here you may iterate and get the attributes of those falling within the draw polygon
for (var z=0;z<featuresOnDrawPoly.length;z++){
console.log("address is ======", featuresOnDrawPoly[z].get('definition'));
}
}).fail(function () {
alert("fail loading layer!!!")
});
})
这是我的 proj4 投影的定义,我阅读了 axis 并想知道这个定义是否有问题?
proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
您需要为 http://www.opengis.net/gml/srs/epsg.xml#27700
创建一个别名到 EPSG:27700
,因为这是 GML 解析器读取的容器 SRS,请参阅:http://openlayers.org/en/v3.14.2/apidoc/ol.proj.html#.addEquivalentProjections
https://github.com/openlayers/ol3/issues/3898#issuecomment-120899034
现在刚遇到这个问题,当使用 OpenLayers 3.17.1 从 GeoServer 2.9.1 加载 WFS 1.1.0 功能时。
GML 中指定的 srsName 是 urn:x-ogc:def:crs:EPSG:3763 所以以下对我有用:
var proj3763 = new ol.proj.Projection({
code: 'EPSG:' + 3763,
extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421],
axis: 'enu'
});
ol.proj.addProjection(proj3763);
var proj3763OGC = new ol.proj.Projection({ // srsName from GeoServer GML3 (WFS)
code: 'urn:x-ogc:def:crs:EPSG:' + 3763,
axis: 'enu',
extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421]
});
ol.proj.addProjection(proj3763OGC);
ol.proj.addEquivalentProjections([proj3763OGC, proj3763]);
我有一个允许用户在地图上绘制多边形的应用程序,然后使用 JSTS 库将多边形与 WFS 图层相交并读取与用户的多边形相交的要素。
用户在地图上绘制 select 多边形后发生错误,返回错误:
'无法读取未定义的 属性 'getAxisOrientation''
这似乎是一个与投影相关的问题(我正在使用 EPSG:27700 投影)。
绘制用户多边形时的代码如下 - 是否需要在 WFS 读取要素方法中包含投影?
draw.on('drawend',function(e){
var extent = e.feature.getGeometry().getExtent();
var geomA = e.feature.getGeometry();
myDrawSource.clear();
mySelectionsSource.clear();
$.ajax('../../geoserver/wfs', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'planning:flood_zone_2',
srsname: 'EPSG:27700',
bbox: extent.join(',') + ',EPSG:27700'
}
}).done(function(resp){
var formatWFS = new ol.format.WFS();
var featuresInExtent = formatWFS.readFeatures(resp);
var featuresOnDrawPoly = new Array();
for (var i=0;i<featuresInExtent.length;i++){
var geomB = featuresInExtent[i].getGeometry();
if (polyIntersectsPoly(geomA,geomB)===true){
featuresOnDrawPoly.push(featuresInExtent[i])
}
}
mySelectionsSource.addFeatures(featuresOnDrawPoly);
//here you may iterate and get the attributes of those falling within the draw polygon
for (var z=0;z<featuresOnDrawPoly.length;z++){
console.log("address is ======", featuresOnDrawPoly[z].get('definition'));
}
}).fail(function () {
alert("fail loading layer!!!")
});
})
这是我的 proj4 投影的定义,我阅读了 axis 并想知道这个定义是否有问题?
proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
您需要为 http://www.opengis.net/gml/srs/epsg.xml#27700
创建一个别名到 EPSG:27700
,因为这是 GML 解析器读取的容器 SRS,请参阅:http://openlayers.org/en/v3.14.2/apidoc/ol.proj.html#.addEquivalentProjections
https://github.com/openlayers/ol3/issues/3898#issuecomment-120899034
现在刚遇到这个问题,当使用 OpenLayers 3.17.1 从 GeoServer 2.9.1 加载 WFS 1.1.0 功能时。
GML 中指定的 srsName 是 urn:x-ogc:def:crs:EPSG:3763 所以以下对我有用:
var proj3763 = new ol.proj.Projection({
code: 'EPSG:' + 3763,
extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421],
axis: 'enu'
});
ol.proj.addProjection(proj3763);
var proj3763OGC = new ol.proj.Projection({ // srsName from GeoServer GML3 (WFS)
code: 'urn:x-ogc:def:crs:EPSG:' + 3763,
axis: 'enu',
extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421]
});
ol.proj.addProjection(proj3763OGC);
ol.proj.addEquivalentProjections([proj3763OGC, proj3763]);