Skip to content

False positives with the spatial intersects filter #29

@Hairo

Description

@Hairo

Hi, im getting false positives when trying to use the intersects spatial filter with a polygon and multipoint:

import 'package:dart_jts/dart_jts.dart';
import 'package:nitrite/nitrite.dart';
import 'package:nitrite_spatial/nitrite_spatial.dart' as nspatial;
import 'package:nitrite_hive_adapter/nitrite_hive_adapter.dart';

void testDB() async {
  final storeModule = HiveModule.withConfig()
              .path("test_data.db")
              .addTypeAdapter(nspatial.GeometryAdapter())
              .build();

  final db = await Nitrite.builder()
              .loadModule(storeModule)
              .loadModule(nspatial.SpatialModule())
              .openOrCreate();

  final collection = await db.getCollection("shapes");
  await collection.createIndex(["geometry"], indexOptions(nspatial.spatialIndex));


  var reader = WKTReader();
  var polygon = reader.read('POLYGON ((40486.563 45036.319, 40084.108 44545.927, 39496.171 44938.774, 39889.018 45526.712, 40486.563 45036.319))') as Polygon;
  var multipoint = reader.read('MULTIPOINT ((40933.744 45423.275), (40395.332 45612.623), (40574.536 45576.665))') as MultiPoint;

  final doc = createDocument("geometry", multipoint);
  await collection.insert(doc);

  final result = collection.find(filter: nspatial.where('geometry').intersects(polygon));
  print(await result.toList());

  await db.close();
}

In this example i should get an empty list when printing at the end but i get the multipoint, ie:

[((geometry, MULTIPOINT ((40933.7439999999987776 45423.2750000000014552), (40395.3320000000021537 45612.6229999999995925), (40574.5360000000000582 45576.6650000000008731), (40943.5990000000019791 45458.6240000000034343), (40957.0190000000002328 45452.4660000000003492), (40960.9420000000027358 45450.6039999999993597), (40951.6900000000023283 45424.0190000000002328), (40951.4179999999978463 45423.8539999999993597), (40933.7439999999987776 45423.2750000000014552))), (_id, 1904237376570642432), (_revision, 1), (_modified, 1742840544251)), ((geometry, MULTIPOINT ((40933.7439999999987776 45423.2750000000014552), (40395.3320000000021537 45612.6229999999995925), (40574.5360000000000582 45576.6650000000008731))), (_id, 1904239157070315520), (_revision, 1), (_modified, 1742840968755))]

These geometries don't intersect each other as seen below:

Image

Using:

  • dart_jts: 0.3.0+1
  • nitrite_spatial: 1.1.0
  • nitrite_hive_adapter: 1.1.0
  • nitrite: 1.1.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions