ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

ST_DWithin

  • Definition
  • Syntax
  • Return type
  • Example

Note:

Oracle and PostgreSQL only

Definition

ST_DWithin takes two geometries as input and returns true if the geometries are within the specified distance of one another; otherwise, false is returned. The spatial reference system of the geometries determines what unit of measure is applied to the specified distance. Therefore, the geometries you provide to ST_DWithin must both use the same coordinate projection and SRID.

Syntax

sde.st_dwithin (st_geometry geometry1, st_geometry geometry2, double_precision distance);

Return type

Boolean

Example

In the following example, two tables are created and features are inserted to them. Next, the ST_DWithin function is used to determine if a point in the first table is within 100 meters of a polygon in the second table.

--Create table to store points.
CREATE TABLE dwithin_test_pt (id INT, geom sde.st_geometry);

--Create table to store polygons.
CREATE TABLE dwithin_test_poly (id INT, geom sde.st_geometry);

--Insert features into each table.

INSERT INTO dwithin_test_pt 
 VALUES
 (
  1,
  sde.st_geometry('point (1 2)', 4326)
 )
;

INSERT INTO dwithin_test_pt
 VALUES
 (
  2,
  sde.st_geometry('point (10.02 20.01)', 4326)
 )
;

INSERT INTO dwithin_test_poly
 VALUES
 (
  1,
  sde.st_geometry('polygon ((10.02 20.01, 11.92 35.64, 25.02 34.15, 19.15 33.94, 10.02 20.01))', 4326)
 )
;

INSERT INTO dwithin_test_poly
 VALUES
 (
  2,
  sde.st_geometry('polygon ((101.02 200.01, 111.92 350.64, 250.02 340.15, 190.15 330.94, 101.02 200.01))', 4326)
 )
;
Next, use ST_DWithin to determine which features in each table are within 100 meters of each other and which are not. The ST_Distance function is included in this statement to show the actual distance between the features.

--Determine which features in the point table are within 100 meters of the features in the polygon table.
SELECT pt.id, poly.id, sde.st_distance(pt.geom, poly.geom) distance_meters, sde.st_dwithin(pt.geom, poly.geom, 100) DWithin
 FROM dwithin_test_pt pt, dwithin_test_poly poly;

The select statement returns the following when run on data in PostgreSQL:

id     id     distance_meters        dwithin
1      1      20.1425048094819       t
1      2      221.837689538996       f
2      1      0                      t
2      2      201.69531476958        f

The statement returns the following when run on data in Oracle:

ID     ID   DISTANCE_METERS   DWITHIN
1      1         20.1425048         1
1      2          221.83769         0
2      1                  0         1
2      2         201.695315         0

In the following example, ST_DWithin is used to find which features are within 300 meters of one another:

--Determine which features in the point table are within 300 meters of the features in the polygon table.
SELECT pt.id, poly.id, sde.st_distance(pt.geom, poly.geom) distance_meters, sde.st_dwithin(pt.geom, poly.geom, 300) DWithin
 FROM dwithin_test_pt pt, dwithin_test_poly poly;

This second select statement returns the following when run on data in PostgreSQL:

id     id     distance_meters        dwithin
1      1      20.1425048094819       t
1      2      221.837689538996       t
2      1      0                      t
2      2      201.69531476958        t

The second select statement returns the following when run on data in Oracle:

ID     ID   DISTANCE_METERS    DWITHIN
1      1         20.1425048          1
1      2          221.83769          1
2      1                  0          1
2      2         201.695315          1

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal