Skip to content

False positives with the spatial intersects filter #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Hairo opened this issue Mar 24, 2025 · 1 comment
Open

False positives with the spatial intersects filter #29

Hairo opened this issue Mar 24, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Hairo
Copy link

Hairo commented Mar 24, 2025

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
@anidotnet
Copy link
Contributor

Thanks for reporting the issue. There is a bug currently in the Nitrite spatial module. There is a work going on in nitrite-java library to address this here. Once that was fix, it will also land here.

@anidotnet anidotnet added the bug Something isn't working label Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants