|
| 1 | +xquery version "3.1"; |
| 2 | + |
| 3 | +module namespace geot="http://xquery.weber-gesamtausgabe.de/modules/geo-tests"; |
| 4 | + |
| 5 | +declare namespace test="http://exist-db.org/xquery/xqsuite"; |
| 6 | +import module namespace geo="http://xquery.weber-gesamtausgabe.de/modules/geo" at "../xquery/geo.xqm"; |
| 7 | + |
| 8 | +declare |
| 9 | + %test:args( |
| 10 | + '{ "type": "Point", "coordinates": [3.5, 2.5] }', |
| 11 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 12 | + ) |
| 13 | + %test:assertTrue |
| 14 | + %test:args( |
| 15 | + '{ "type": "Point", "coordinates": [0.0, 5.0] }', |
| 16 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 17 | + ) |
| 18 | + %test:assertFalse |
| 19 | + %test:args( |
| 20 | + '{ "type": "Point", "coordinates": [5.0, 0.0] }', |
| 21 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 22 | + ) |
| 23 | + %test:assertFalse |
| 24 | + %test:args( |
| 25 | + '{ "type": "Point", "coordinates": [5.0, 2.5] }', |
| 26 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 27 | + ) |
| 28 | + %test:assertFalse |
| 29 | + %test:args( |
| 30 | + '{ "type": "Point", "coordinates": [3.5, 7.5] }', |
| 31 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 32 | + ) |
| 33 | + %test:assertFalse |
| 34 | + %test:args( |
| 35 | + '{ "type": "Point", "coordinates": [5.0, 7.5] }', |
| 36 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 37 | + ) |
| 38 | + %test:assertFalse |
| 39 | + function geot:test-point-in-ring($point as xs:string, $ring as xs:string) as xs:boolean { |
| 40 | + geo:point-in-ring($point => parse-json(), $ring => parse-json()) |
| 41 | +}; |
| 42 | + |
| 43 | +declare |
| 44 | + %test:args( |
| 45 | + '{ "type": "Point", "coordinates": [3.5, 2.5] }', |
| 46 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 47 | + ) |
| 48 | + %test:assertFalse |
| 49 | + %test:args( |
| 50 | + '{ "type": "Point", "coordinates": [0.0, 5.0] }', |
| 51 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 52 | + ) |
| 53 | + %test:assertTrue |
| 54 | + %test:args( |
| 55 | + '{ "type": "Point", "coordinates": [5.0, 0.0] }', |
| 56 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 57 | + ) |
| 58 | + %test:assertTrue |
| 59 | + %test:args( |
| 60 | + '{ "type": "Point", "coordinates": [5.0, 2.5] }', |
| 61 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 62 | + ) |
| 63 | + %test:assertTrue |
| 64 | + %test:args( |
| 65 | + '{ "type": "Point", "coordinates": [3.5, 7.5] }', |
| 66 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 67 | + ) |
| 68 | + %test:assertFalse |
| 69 | + %test:args( |
| 70 | + '{ "type": "Point", "coordinates": [5.0, 7.5] }', |
| 71 | + '[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]' |
| 72 | + ) |
| 73 | + %test:assertFalse |
| 74 | + function geot:test-point-on-edge($point as xs:string, $ring as xs:string) as xs:boolean { |
| 75 | + geo:point-on-edge($point => parse-json(), $ring => parse-json()) |
| 76 | +}; |
| 77 | + |
| 78 | +declare |
| 79 | + %test:args( |
| 80 | + '{ "type": "Point", "coordinates": [2.5, 2.5] }', |
| 81 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 82 | + ) |
| 83 | + %test:assertTrue |
| 84 | + %test:args( |
| 85 | + '{ "type": "Point", "coordinates": [2.5, 2.5] }', |
| 86 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ], [ [1.0, 1.0], [1.0, 4.0], [4.0, 4.0], [4.0, 1.0], [1.0, 1.0] ]]}' |
| 87 | + ) |
| 88 | + %test:assertFalse |
| 89 | + %test:args( |
| 90 | + '{ "type": "Point", "coordinates": [4, 4.43832400000014] }', |
| 91 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ], [ [1.0, 1.0], [1.0, 4.0], [4.0, 4.0], [4.0, 1.0], [1.0, 1.0] ]]}' |
| 92 | + ) |
| 93 | + %test:assertTrue |
| 94 | + %test:args( |
| 95 | + '{ "type": "Point", "coordinates": [4, 4.43832400000014] }', |
| 96 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 97 | + ) |
| 98 | + %test:assertTrue |
| 99 | + %test:args( |
| 100 | + '{ "type": "Point", "coordinates": [0.0, 5.0] }', |
| 101 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 102 | + ) |
| 103 | + %test:assertTrue |
| 104 | + %test:args( |
| 105 | + '{ "type": "Point", "coordinates": [5.0, 0.0] }', |
| 106 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 107 | + ) |
| 108 | + %test:assertTrue |
| 109 | + %test:args( |
| 110 | + '{ "type": "Point", "coordinates": [5.0, 2.5] }', |
| 111 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 112 | + ) |
| 113 | + %test:assertTrue |
| 114 | + %test:args( |
| 115 | + '{ "type": "Point", "coordinates": [3.5, 7.5] }', |
| 116 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 117 | + ) |
| 118 | + %test:assertFalse |
| 119 | + %test:args( |
| 120 | + '{ "type": "Point", "coordinates": [5.0, 7.5] }', |
| 121 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ]] }' |
| 122 | + ) |
| 123 | + %test:assertFalse |
| 124 | + %test:args( |
| 125 | + '{ "type": "Point", "coordinates": [2, 4] }', |
| 126 | + '{ "type": "Polygon", "coordinates": [[ [0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0] ], [ [1.0, 1.0], [1.0, 4.0], [4.0, 4.0], [4.0, 1.0], [1.0, 1.0] ]]}' |
| 127 | + ) |
| 128 | + %test:assertFalse |
| 129 | + %test:args( |
| 130 | + '{ "foo": "bar" }', |
| 131 | + '{ "bli": "baz" }' |
| 132 | + ) |
| 133 | + %test:assertError("GeojsonFormatError") |
| 134 | + function geot:test-point-in-polygon($point as xs:string, $polygon as xs:string) as xs:boolean { |
| 135 | + geo:point-in-polygon($point => parse-json(), $polygon => parse-json()) |
| 136 | +}; |
0 commit comments