lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "david.w.smiley@gmail.com" <david.w.smi...@gmail.com>
Subject Re: [spatial] Indexing polygons?
Date Mon, 11 Jan 2016 05:53:33 GMT
Hi Robert,

First, for the basics of the spatial module, see SpatialExample.java in the
tests area.  It doesn't include a polygon example but shows the concepts of
a SpatialContext, Shape, and SpatialStrategy which are the key abstractions.

The default SpatialContext implementation doesn't handle polygons -- not
yet any way.  So use JtsSpatialContext.GEO or some other configured variant
created via JtsSpatialContextFactory and add JTS to your classpath (LGPL
licensed, by the way).  With that, you can create polygons parsed from WKT
or GeoJSON -- see the SpatialContext.getFormats().getWktReader() for
example.  That'll produce a Shape instance parsed from a polygon WKT string
you give it.  Then re-aquaint yourself with SpatialExample.java to see how
to index a Shape and how to query by a Shape.  An important difference with
the example is the choice of an appropriate SpatialStrategy.  The example
uses RecursivePrefixTreeStrategy which is best for points-only data;
otherwise I recommend CompositeSpatialStrategy.

I'm actively working on a SpatialContext implementation for "Geo3d" which
will be another option.  Your code wouldn't change other than choosing a
different SpatialContext impl.

By the way, the one-liner in your email I see you found in
SpatialExample.java:
  doc.add(new StoredField(strategy.getFieldName, pt.getX + " " + pt.getY))
-- is purely for the "stored" version (for document retrieval in search
results); not for indexing/search.  See the comments preceding it ;-)

Good luck.  And sorry for leaving you hanging for a few days; I overlooked
your email.
~ David

On Wed, Jan 6, 2016 at 10:59 PM Robert Nix <rob@spatially.com> wrote:

> Hi,
>
> Is there an example in the lucene-solr source to show how to index polygons
> and how to search with and for indexed polys? I'm looking in
> lucene/spatial/src/test/ and I see an example of a point and it seems
> obvious:
>
> doc.add(new StoredField(strategy.getFieldName, pt.getX + " " + pt.getY))
>
> But nothing regarding polygons is jumping out at me. If there isn't such an
> example, can someone provide a short one?
>
> Thanks
> --
> --nix
>
-- 
Lucene/Solr Search Committer, Consultant, Developer, Author, Speaker
LinkedIn: http://linkedin.com/in/davidwsmiley | Book:
http://www.solrenterprisesearchserver.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message