Name

ST_AsEncodedPolyline — 从线串几何图形返回编码的多段线。

Synopsis

text ST_AsEncodedPolyline(geometry geom, integer precision=5);

描述

将几何图形作为编码的多段线返回。精度为5的Google Maps和精度为5和6的Open Source Routing Machine使用此格式。

可选 precision 指定将在编码多段线中保留的小数位数。编码和解码的值应该是相同的,否则坐标会错误。

可用性:2.2.0

示例

基本信息

SELECT ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)'));
        --result--
        |_p~iF~ps|U_ulLnnqC_mqNvxq`@
        

与地理线串和地理分段结合使用,并放在谷歌地图上

-- the SQL for Boston to San Francisco, segments every 100 KM
        SELECT ST_AsEncodedPolyline(
                ST_Segmentize(
                        ST_GeogFromText('LINESTRING(-71.0519 42.4935,-122.4483 37.64)'),
                                100000)::geometry) As encodedFlightPath;

当您用查询结果替换$VARIABLE时,JavaScript将如下所示

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<script type="text/javascript">
         flightPath = new google.maps.Polyline({
                        path:  google.maps.geometry.encoding.decodePath("$encodedFlightPath"),
                        map: map,
                        strokeColor: '#0000CC',
                        strokeOpacity: 1.0,
                        strokeWeight: 4
                });
</script>
        

另请参阅

ST_LineFromEncodedPolyline, ST_Segmentize