GISarabia.org
PostGIS › الدليل الرسمي › 7. مرجع PostGIS › 7.11.2. علاقات المسافة
PostGIS 3.6 · Official Manual · ترجمة عربية

ST_DWithin

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

الاسم

ST_DWithin — تختبر ما إذا كان شكلان هندسيان ضمن مسافة معيّنة

المختصر

boolean ST_DWithin(geometry g1, geometry g2, double precision distance_of_srid);

boolean ST_DWithin(geography gg1, geography gg2, double precision distance_meters, boolean use_spheroid = true);

الوصف

تُعيد true إذا كان الشكلان الهندسيان ضمن مسافة معيّنة

بالنسبة إلى geometry: تُحدَّد المسافة بالوحدات المعرّفة في النظام المرجعي المكاني للأشكال الهندسية. لكي يكون لهذه الدالة معنى، يجب أن تكون الأشكال المصدرية في نفس نظام الإحداثيات (لها نفس SRID).

بالنسبة إلى geography: الوحدات بالأمتار، ويكون قياس المسافة افتراضيًا use_spheroid = true. لتقييم أسرع استخدم use_spheroid = false للقياس على الكرة.

[ملاحظة]

استخدم ST_3DDWithin للأشكال الهندسية الثلاثية الأبعاد.

[ملاحظة]

يتضمن استدعاء هذه الدالة مقارنةً للمستطيل المحيط تستفيد من أي فهارس متاحة على الأشكال الهندسية.

تطبّق هذه الدالة مواصفة OGC Simple Features Implementation Specification for SQL 1.1.

متاحة منذ: 1.5.0 أُضيف دعم geography

حُسّنت في: 2.1.0 تحسين سرعة geography. انظر جعل geography أسرع للتفاصيل.

حُسّنت في: 2.1.0 أُضيف دعم الأشكال الهندسية المنحنية.

قبل الإصدار 1.3، كانت ST_Expand تُستخدم عادةً مع && وST_Distance لاختبار المسافة، وفي الإصدارات السابقة لـ 1.3.4 كانت هذه الدالة تستخدم ذلك المنطق. منذ 1.3.4 تستخدم ST_DWithin دالة مسافة أسرع ذات اختصار في التقييم (short-circuit).

أمثلة

-- Find the nearest hospital to each school
-- that is within 3000 units of the school.
--  We do an ST_DWithin search to utilize indexes to limit our search list
--  that the non-indexable ST_Distance needs to process
-- If the units of the spatial reference is meters then units would be meters
SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.geom, h.hospital_name
  FROM schools s
    LEFT JOIN hospitals h ON ST_DWithin(s.geom, h.geom, 3000)
  ORDER BY s.gid, ST_Distance(s.geom, h.geom);

-- The schools with no close hospitals
-- Find all schools with no hospital within 3000 units
-- away from the school.  Units is in units of spatial ref (e.g. meters, feet, degrees)
SELECT s.gid, s.school_name
  FROM schools s
    LEFT JOIN hospitals h ON ST_DWithin(s.geom, h.geom, 3000)
  WHERE h.gid IS NULL;

-- Find broadcasting towers that receiver with limited range can receive.
-- Data is geometry in Spherical Mercator (SRID=3857), ranges are approximate.

-- Create geometry index that will check proximity limit of user to tower
CREATE INDEX ON broadcasting_towers using gist (geom);

-- Create geometry index that will check proximity limit of tower to user
CREATE INDEX ON broadcasting_towers using gist (ST_Expand(geom, sending_range));

-- Query towers that 4-kilometer receiver in Minsk Hackerspace can get
-- Note: two conditions, because shorter LEAST(b.sending_range, 4000) will not use index.
SELECT b.tower_id, b.geom
  FROM broadcasting_towers b
  WHERE ST_DWithin(b.geom, 'SRID=3857;POINT(3072163.4 7159374.1)', 4000)
    AND ST_DWithin(b.geom, 'SRID=3857;POINT(3072163.4 7159374.1)', b.sending_range);

        

انظر أيضًا

ST_Distance, ST_3DDWithin