Search code examples
xmlcoordinatesxquerycollision-detectionarea

Check if a shape is within the bounds of another shape using only x,y coords and shape area (2D)


So I have a XML database filled with data about different islands and lakes in the world and I want to select all lakes which have at least one island in them. Problem is that the only relevant data I have about each is their longitude, latitude and their total area.

Island XML example:

<island id="island-Svalbard" country="SVAX" sea="sea-ArcticOcean sea-Greenlandsea sea-NorwegianSea sea-BarentsSea">
  <name>Svalbard</name>
  <islands>Svalbard</islands>
  <area>39044</area>
  <latitude>78.9</latitude>
  <longitude>18.2</longitude>
  <elevation>1713</elevation>
</island>

Lake XML example:

<lake id="lake-LagunaCarbon" country="RA" type="saline">
  <name>Laguna del Carbón</name>
  <located country="RA" province="prov-Argentina-20"/>
  <area>9</area>
  <latitude>-49.58</latitude>
  <longitude>-68.35</longitude>
  <elevation>-105</elevation>
  <depth>0</depth>
</lake>

So how do I check if an island is within the bounds of a lake using only this information? Is it even possible?

Current (unfinished) Xquery:

let $doc := doc("mondial.xml")/mondial
let $lakes := $doc/lake
let $islands := $doc/island

let $lakesWithIslands := (
  for $l in $lakes
  let $lLong := $l/data(longitude)
  let $lLat := $l/data(latitude)
  let $lArea := $l/data(area)
    for $i in $islands
     let $iLong := $i/data(longitude)
     let $iLat := $i/data(latitude)
     let $iArea := $i/data(area)
     where (something)
  return $l
)

return $lakesWithIslands

Any help is appreciated. Thanks!


Solution

  • Turns out that there actually was a @lake attribute in the island elements that I could use to figure out which which lake an island was in and then use that to figure out which lakes that had islands in them. This was pointed out by @LeoWörteler in the comments. So my problem actually got a completely different solution.