geo:crosses( $region-1 as cts:region, $region-2 as cts:region, [$options as xs:string*] ) as xs:boolean
Compares geospatial regions to see if they fulfill the 'crosses' DE-9IM relation.
This function determines whether the two regions
R1=$region-1
and R2=$region-2
satisfy the relationship R1 crosses 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.
xquery version "1.0-ml"; let $r1 := cts:polygon("POLYGON((-122.427520751953 37.6555576956251,-122.459106445313 37.5658069549294,-122.289505004883 37.5946477878735,-122.427520751953 37.6555576956251))") let $r2 := cts:linestring("LINESTRING(-122.571029663086 37.5728821555562,-122.400054931641 37.6077041124284,-122.161102294922 37.5696167618573)") return geo:crosses($r1,$r2,("coordinate-system=wgs84/double")) (: returns true :)
xquery version "1.0-ml"; import module namespace op = 'http://marklogic.com/optic' at 'MarkLogic/optic.xqy'; import module namespace ogeo = 'http://marklogic.com/optic/expression/geo' at 'MarkLogic/optic/optic-geo.xqy'; (: Optic example using the Value Processing Function ogeo:crosses() :) let $linestringLit := 'LINESTRING(-77.56535787898146 36.47692315351092,-79.03752584773146 34.61780445863212,-80.48772116023146 33.41581817447875,-81.36662741023146 31.917629384303023)' let $plan:= op:from-view('buildings', 'builds') =>op:where(ogeo:crosses(op:col('poly'),$linestringLit)) =>op:select(('name', op:col('geoid'))) =>op:order-by('geoid') return $plan=>op:result() (: ==> rows representing names and geoids where the 'poly' column CROSSES linestringLit (a rough highway 95) :)
xquery version "1.0-ml"; (: SQL example using the ST_Crosses function :) let $map := map:new(map:entry('linestringLit','LINESTRING(-77.56535787898146 36.47692315351092,-79.03752584773146 34.61780445863212,-80.48772116023146 33.41581817447875,-81.36662741023146 31.917629384303023)')) return xdmp:sql("select * from builds where ST_Crosses(poly,@linestringLit) order by geoid limit 20", (), $map) (: ==> returns rows whose 'poly' column match the DE-9IM relationship CROSSES with the provided WKT linestring :)
xquery version "1.0-ml"; (: GeoSPARQL example using geof:sfCrosses() :) let $map := map:new(map:entry('hwy','LINESTRING(-77.56535787898146 36.47692315351092,-79.03752584773146 34.61780445863212,-80.48772116023146 33.41581817447875,-81.36662741023146 31.917629384303023)')) let $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:sfCrosses(?o, ?hwy, ''coordinate-system=raw'') } ORDER BY ?s' return sem:sparql($query,$map) (: ==> rows representing geometries in a triple's object in the raw coordinate system that fulfill the CROSSES DE-9IM relation with the WKT linestring 'hwy', ordered by subject :)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.