Multipolygon support in Lucene .net

134 Views Asked by At

I am trying to learn lucene .net spatial capabilities .

I want to find if a point exist inside a multi-polygon or not.

From my studies on google, I understand I need to use Net topology suite to describe the multi polygon.

but i am unable to find Lucene.Net.Contrib.Spatial.NTS for the latest version.

Any suggestions (i am using .net core)

2

There are 2 best solutions below

0
On

I'm not familiar with the specific spatial features of Lucene.Net yet but perhaps this NtsPolygonTest will be of help since it appears to be a test of just the type of functionality you are looking for.

I do see that most of the features for spatial live in the Lucene.Net.Spatial namespace (and below).

Also, it looks like the Spatial features use the Spatial4n nuget package which is a port of the Spacial4J java library.

0
On

A lot of this confusion is centered around a couple of things:

New Lucene Design

Lucene 4.x+ is a completely different design than prior versions. The Lucene.Net.Contrib package is no longer part of that design. Instead, there are now specialized modules for different functionality. In this case, what you are looking for is the Lucene.Net.Spatial assembly.

Spatial4n no longer duplicates types

In Spatial4n 0.3.0, Spatial4n.Core.NTS included copies of all of the types of Spatial4n.Core. This meant that you could not reference both libraries at the same time because they had conflicting type names. It required Lucene.Net.Contrib.Spatial to also duplicate types (in Lucene.Net.Contrib.Spatial.NTS) in order to access the functionality of NetTopologySuite.

Since Spatial4n 0.4.1, Spatial4n.Core types are not included in Spatial4n.Core.NTS. Instead Spatial4n.Core.NTS references Spatial4n.Core.

This means in Lucene.NET 4.8 there is no need to have a separate Lucene.Net.Spatial.NTS library that references Spatial4n.Core.NTS (and its duplicate type system of Spatial4n.Core). However, you can add the NTS functionality to your project by referencing Spatial4n.Core.NTS directly.

<ItemGroup>
  <PackageReference Include="Spatial4n.Core" Version="0.4.1" />
  <PackageReference Include="Spatial4n.Core.NTS" Version="0.4.1" />
</ItemGroup>

Examples

As Ron C correctly pointed out, there are some basic tests of NetTopologySuite (NTS) functionality in the Lucene.Net 4.8.0 codebase. But as noted above, you need to reference Spatial4n.Core.NTS to access the extensions for NTS.

There are also some additional tests for Spatial4n using NetTopologySuite that can be analyzed.

If you need more specific information about the functionality, I suggest you search for the Java examples using the terms "Lucene spatial JTS", "Spatial4j", and "JavaTopologySuite". Since the port is done line-by-line for the most part, the Java examples should be fairly easy to translate to .NET.