[英]convert multiline string to line string
i have a set of data that needs to be in linestring only before being converted to geojson, tried using st_dump to convert the st_makeline portion of the code which works fine but then i am having an issue converting it back to geojson, here is the code " limited to select only on this dataset"我有一组数据只需要在转换为 geojson 之前位于线串中,尝试使用 st_dump 转换代码的 st_makeline 部分工作正常但是我在将它转换回 geojson 时遇到问题,这是代码“仅限于此数据集上的 select”
select geo from (
SELECT
routeID , json_extract(st_asgeojson(st_makeline(array_agg(st_geogpoint(locs.lon,
locs.lat) order by locs.date))),'$.coordinates' )as geo,
FROM
howardcounty.routebatches
cross join UNNEST(locations) as locs
where locs.date between {{start_date}} and {{end_date}}
group by routeID
order by routeID
limit 100
)where length(geo) -length(replace(geo,"[","")) > 1+2
this is the error when inserting st_dump这是插入 st_dump 时的错误
json_extract(st_asgeojson(st_dump(st_makeline(array_agg(st_geogpoint(locs.lon, locs.lat) order by locs.date)))),'$.coordinates' )as geo,
before json_extract在 json_extract 之前
after json_extract
在 json_extract 之后
ST_Dump
returns an array of GEOGRAPHY
objects, while ST_AsGeoJson
converts a single GEOGRAPHY
to string. ST_Dump
返回一组GEOGRAPHY
对象,而ST_AsGeoJson
将单个GEOGRAPHY
转换为字符串。 If the desired output shape is for each line in the multilinestring to be on a separate row, the query needs to flatten that array using UNNEST
, similar to how locations are UNNEST
'ed here.如果所需的 output 形状是多线字符串中的每一行都在单独的行上,则查询需要使用
UNNEST
展平该数组,类似于此处对位置进行UNNEST
编辑的方式。
Sample query样本查询
with sample_data as (
select 1 id, st_geogfromtext('multilinestring((1 2, 3 4), (5 6, 7 8))') lines
)
select id, line
from sample_data d, unnest(st_dump(d.lines)) line
Result:结果:
id line
1 "LINESTRING(1 2, 3 4)"
1 "LINESTRING(5 6, 7 8)"
Although it isn't clear from the documentation, the flatten function in the PD Turfjs library does a very good job of this.尽管从文档中看不清楚,但 PD Turfjs 库中的 flatten function 在这方面做得很好。 Pass any "multi" class to it and it will simplify the array structure.
将任何“多”class 传递给它,它将简化数组结构。 It returns a feature collection with the modified record as a member.
它返回一个特征集合,其中包含修改后的记录作为成员。 Example of application here:
这里的应用示例:
'var pobject=JSON.parse(rec);
//
// flatten and stringify if MultiLineString
//
if (pobject.geometry.type=="MultiLineString")
{
var tmpobj=turf.flatten(pobject);
rec=JSON.stringify(tmpobj.features[0]);
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.