Javascript 删除GeoJson高程值的小数
我有一个GeoJson文件,如下所示:Javascript 删除GeoJson高程值的小数,javascript,regex,geojson,Javascript,Regex,Geojson,我有一个GeoJson文件,如下所示: { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "first" }, "geometry": { "type": "LineString", "coordinates": [ [ 22.59323, 44.71464, 233.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "first"
},
"geometry": {
"type": "LineString",
"coordinates": [
[
22.59323,
44.71464,
233.6
],
[
22.59274,
44.71425,
231.8
],
[
22.59264,
44.71405,
230.7
],.........
坐标中的每三个值表示该点的高程。是否有任何(非手动)方法可以从该值中删除小数?我想到了一些类似正则表达式的东西,使用记事本++,但我不知道怎么做 可以使用正则表达式。您可以尝试在一行中查找几个数字,后跟一个点
/((\d\d\d?)\(.*)/
找到两到三位数字、一个点,然后找到行上的任何其他数字。您可以使用以下方式替换它:
\1\2
。它将第一位置于括号内,第二位(不含句点)。在特征上循环,然后在几何体上循环,并在立面上使用Math.floor()
:
featureCollection.features.forEach(function (feature) {
feature.geometry.coordinates.forEach(function (coordinates) {
coordinates[2] = Math.floor(coordinates[2]);
});
});
是的,使用javascript以坐标为目标,并使用
Math.floor
我想你会想要对它们进行舍入?为什么不直接读取坐标舍入中的所有内容,然后放回那里?这很好,尽管我不确定用新值保存旧文件的最佳方法是什么