GISarabia.org
PostGIS › الدليل الرسمي › 7. مرجع PostGIS › 7.19. الإسناد الخطي
PostGIS 3.6 · Official Manual · ترجمة عربية

ST_LineLocatePoint

الصفحة الأصلية بالإنجليزية postgis.net ↗

الاسم

ST_LineLocatePoint — تُعيد الموقع الكسري لأقرب نقطة على خط إلى نقطة.

المختصر

float8 ST_LineLocatePoint(geometry a_linestring, geometry a_point);

float8 ST_LineLocatePoint(geography a_linestring, geography a_point, boolean use_spheroid = true);

الوصف

تُعيد عددًا عشريًا بين 0 و1 يمثّل موقع أقرب نقطة على LineString إلى النقطة المعطاة، كنسبة من طول الخط ثنائي الأبعاد.

يمكنك استخدام الموقع المُعاد لاستخراج نقطة (ST_LineInterpolatePoint) أو جزء من الخط (ST_LineSubstring).

هذا مفيد لتقدير أرقام العناوين

متاحة منذ: 1.1.0

تغيّرت في: 2.1.0. حتى الإصدار 2.0.x كانت تُسمّى ST_Line_Locate_Point.

أمثلة

--Rough approximation of finding the street number of a point along the street
--Note the whole foo thing is just to generate dummy data that looks
--like house centroids and street
--We use ST_DWithin to exclude
--houses too far away from the street to be considered on the street
SELECT ST_AsText(house_loc) As as_text_house_loc,
        startstreet_num +
                CAST( (endstreet_num - startstreet_num)
                        * ST_LineLocatePoint(street_line, house_loc) As integer) As street_num
FROM
(SELECT ST_GeomFromText('LINESTRING(1 2, 3 4)') As street_line,
        ST_Point(x*1.01,y*1.03) As house_loc, 10 As startstreet_num,
                20 As endstreet_num
FROM generate_series(1,3) x CROSS JOIN generate_series(2,4) As y)
As foo
WHERE ST_DWithin(street_line, house_loc, 0.2);

 as_text_house_loc | street_num
-------------------+------------
 POINT(1.01 2.06)  |         10
 POINT(2.02 3.09)  |         15
 POINT(3.03 4.12)  |         20

 --find closest point on a line to a point or other geometry
 SELECT ST_AsText(ST_LineInterpolatePoint(foo.the_line, ST_LineLocatePoint(foo.the_line, ST_GeomFromText('POINT(4 3)'))))
FROM (SELECT ST_GeomFromText('LINESTRING(1 2, 4 5, 6 7)') As the_line) As foo;
   st_astext
----------------
 POINT(3 4)