
geo.touches( region-1 as cts.region, region-2 as cts.region, [options as String[]] ) as Boolean
Compares geospatial regions to see if they fulfill the 'touches' DE-9IM relation.
This function determines whether the two regions
R1=region-1 and R2=region-2
satisfy the relationship R1 touches R2.
The operations are defined by the Dimensionally Extended nine-Intersection Model (DE-9IM) of spatial relations.
The value of the precision option takes precedence over
that implied by the governing coordinate system name, including the
value of the coordinate-system option. For example, if the
governing coordinate system is "wgs84/double" and the precision
option is "float", then the operation uses single precision.
If region-1 or region-2 is a column, the column's
coordinate system will take precedence over the coordinate-system option.
If both region-1 and region-2 are columns, the query
will run unoptimized. Queries with one region column and a region literal will be
optimized.
const r1 = cts.polygon("POLYGON((-122.40042014176004 37.62072625775772,-122.38359732681863 37.60196035656762,-122.3657445436155 37.62154205908579,-122.40042014176004 37.62072625775772))");
const r2 = cts.point("POINT(-122.40042014176004 37.62072625775772)");
geo.touches(r1,r2,['coordinate-system=wgs84','precision=double'])
// returns true
// Optic example using the Value Processing Function op.geo.touches()
const op = require('/MarkLogic/optic');
var polygonLit =
`POLYGON((-109.05489567149378 37.007687849517886,-109.05489567149378 31.321594772151634,
-108.19796207774378 31.39664652828848,-108.26388004649378 31.827028203476246,
-106.52804020274378 31.808357379968474,-106.55001285899378 32.08802274501026,
-103.03438785899378 32.03215780670212,-103.01241520274378 37.025232193318125,
-109.05489567149378 37.007687849517886))`
const result=op.fromView('buildings', 'builds')
.where(op.geo.touches(op.col('poly'),polygonLit))
.select([op.col('name'), op.col('geoid')])
.orderBy('geoid')
.result()
result;
// ==>
// rows representing names and geoids where the 'poly' column TOUCHES polygonLit (a rough New Mexico representation)
'use strict';
// SQL example using the ST_Touches function
const literal =
{"polyLit":
`POLYGON((-83.74086287706339 35.30705888366864,
-82.57081893175089 35.30705888366864,
-82.57081893175089 33.64983884507408,
-83.74086287706339 33.64983884507408,
-83.74086287706339 35.30705888366864))`}
var result = xdmp.sql('select * from builds where ST_Touches(poly,@polyLit) order by geoid limit 20', null, literal);
result;
// ==>
// returns rows whose 'poly' column match the DE-9IM relationship TOUCHES with the provided WKT polygon
'use strict';
const op = require('/MarkLogic/optic');
// GeoSPARQL example using geof:sfTouches()
var poly =
{
poly:
'POLYGON((-83.74086287706339 35.30705888366864,-82.57081893175089 35.30705888366864,\
-82.57081893175089 33.64983884507408,-83.74086287706339 33.64983884507408,\
-83.74086287706339 35.30705888366864))'
}
var query =
`
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geoml: <http://marklogic.com/geospatial#>
PREFIX cts: <http://marklogic.com/cts#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT *
WHERE { ?s my:hasExactGeometry ?o
FILTER geof:sfTouches(?o, ?poly, 'coordinate-system=wgs84')
}
ORDER BY ?s`
sem.sparql(query,poly)
// ==>
// rows representing geometries in a triple's object in the wgs84 coordinate system
// that fulfill the TOUCHES DE-9IM relation with the WKT polygon 'poly', ordered by subject
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.