打开图层 - 格式指向多面体
Open layers - format points to multipolygon
我正在使用两种不同的服务,第一种 returns 是多边形,如下所示:
0: {type: "Feature", id: "postal_fsa_boundaries.1590", geometry: {type: "Polygon",…},…}
geometry: {type: "Polygon",…}
coordinates: [[[-123.09689608, 49.24042409], [-123.09391444, 49.24036854], [-123.09340615, 49.24035906],…]]
type: "Polygon"
geometry_name: "boundary"
id: "postal_fsa_boundaries.1590"
第二个服务,returns一个有坐标的点,像这样:
features: [{type: "Feature", id: "active_address.fid-31c7b976_175e990a2fb_664a",…},…]
0: {type: "Feature", id: "active_address.fid-31c7b976_175e990a2fb_664a",…}
geometry: {type: "Point", coordinates: [-114.0926087, 51.05883014]}
coordinates: [-114.0926087, 51.05883014]
type: "Point"
geometry_name: "the_geom"
id: "active_address.fid-31c7b976_175e990a2fb_664a"
目前要解析对多边形的响应,我正在使用:
const multi = new MultiPolygon(fsas.map((f) => f.geometry));
其中 geomety
类型为 Polygon
。
现在解析它我得到:
new WKT().writeGeometry(multi)
我收到这样的回复:
((
51.05301895 -114.09479052,51.05305604 -114.09397244,51.05338313 -114.09335017,51.05341011 -114.09167379,51.05706864 -114.0917623,51.0571091 -114.08597946,51.05952998 -114.08607602,51.05956032 -114.09473956,51.05301895 -114.09479052)), ((
51.05301895 -114.09479052,51.05305604 -114.09397244,51.05338313 -114.09335017,51.05341011 -114.09167379,51.05706864 -114.0917623,51.0571091 -114.08597946,51.05952998 -114.08607602,51.05956032 -114.09473956,51.05301895 -114.09479052))
正如我所料。
但是我没有找到对 Point
.
做同样事情的方法
有人知道如何正确格式化它们吗?
我只是在使用 Point([])
但我可以更改它
以下代码
const addresses = [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-114.0926087, 51.05883014]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-115.0926087, 52.05883014]
}
}];
const multi = new ol.geom.MultiPolygon([[addresses.map((f) => f.geometry.coordinates)]]);
console.log(new ol.format.WKT().writeGeometry(multi));
生产
MULTIPOLYGON(((-114.0926087 51.05883014,-115.0926087 52.05883014)))
在浏览器中。是不是有点接近了?
我正在使用两种不同的服务,第一种 returns 是多边形,如下所示:
0: {type: "Feature", id: "postal_fsa_boundaries.1590", geometry: {type: "Polygon",…},…}
geometry: {type: "Polygon",…}
coordinates: [[[-123.09689608, 49.24042409], [-123.09391444, 49.24036854], [-123.09340615, 49.24035906],…]]
type: "Polygon"
geometry_name: "boundary"
id: "postal_fsa_boundaries.1590"
第二个服务,returns一个有坐标的点,像这样:
features: [{type: "Feature", id: "active_address.fid-31c7b976_175e990a2fb_664a",…},…]
0: {type: "Feature", id: "active_address.fid-31c7b976_175e990a2fb_664a",…}
geometry: {type: "Point", coordinates: [-114.0926087, 51.05883014]}
coordinates: [-114.0926087, 51.05883014]
type: "Point"
geometry_name: "the_geom"
id: "active_address.fid-31c7b976_175e990a2fb_664a"
目前要解析对多边形的响应,我正在使用:
const multi = new MultiPolygon(fsas.map((f) => f.geometry));
其中 geomety
类型为 Polygon
。
现在解析它我得到:
new WKT().writeGeometry(multi)
我收到这样的回复:
(( 51.05301895 -114.09479052,51.05305604 -114.09397244,51.05338313 -114.09335017,51.05341011 -114.09167379,51.05706864 -114.0917623,51.0571091 -114.08597946,51.05952998 -114.08607602,51.05956032 -114.09473956,51.05301895 -114.09479052)), (( 51.05301895 -114.09479052,51.05305604 -114.09397244,51.05338313 -114.09335017,51.05341011 -114.09167379,51.05706864 -114.0917623,51.0571091 -114.08597946,51.05952998 -114.08607602,51.05956032 -114.09473956,51.05301895 -114.09479052))
正如我所料。
但是我没有找到对 Point
.
有人知道如何正确格式化它们吗?
我只是在使用 Point([])
但我可以更改它
以下代码
const addresses = [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-114.0926087, 51.05883014]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-115.0926087, 52.05883014]
}
}];
const multi = new ol.geom.MultiPolygon([[addresses.map((f) => f.geometry.coordinates)]]);
console.log(new ol.format.WKT().writeGeometry(multi));
生产
MULTIPOLYGON(((-114.0926087 51.05883014,-115.0926087 52.05883014)))
在浏览器中。是不是有点接近了?