Find all buildings having one or more nested bldg:GroundSurface features whose bldg:lod2MultiSurface property is disjoint with a given 2D polygon

XML Query

<query xmlns="http://www.3dcitydb.org/importer-exporter/config">
  <typeNames>
    <typeName xmlns:bldg="http://www.opengis.net/citygml/building/2.0">bldg:Building</typeName>
  </typeNames>
  <filter>
    <disjoint>
      <valueReference>bldg:boundedBy/bldg:GroundSurface/bldg:lod2MultiSurface</valueReference>
      <polygon>
        <exterior>35 10 45 45 15 40 10 20 35 10</exterior>
      </polygon>
    </disjoint>
  </filter>
</query>

SQL Query for 3DCityDB v4 (PostgreSQL)

select
  distinct b.id,
  b.objectclass_id,
  b.gmlid
from
  citydb.building a
  inner join citydb.cityobject b on a.id = b.id
  inner join citydb.thematic_surface c on (
    a.id = c.building_id
    and c.objectclass_id = 35
  )
where
  b.objectclass_id = 26
  and c.lod2_multi_surface_id is not null
  and (
    not (
      b.envelope & & 'SRID=3857;POLYGON((10 10,45 10,45 45,10 45,10 10))'
      and exists (
        select
          d.id
        from
          citydb.surface_geometry d
        where
          d.root_id = c.lod2_multi_surface_id
          and d.geometry is not null
          and ST_Intersects(d.geometry, 'SRID=3857;POLYGON((35 10,45 45,15 40,10 20,35 10))') = 'TRUE'
      )
    )
  )