Re: [Dev] spatial4j

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] spatial4j

dsmiley
Hi again Bruce,


On Tue, Feb 18, 2014 at 8:34 AM, Bruce Hartzler <[hidden email]> wrote:
Hi David,

Well, I started the upgrade today. Ran into some problems pretty quickly

The worldBounds change took me a while to figure out (I know it's in the Changes.md file but you might want to highlight it a bit more). You probably also want to update the page at: https://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 which still has the old style or https://cwiki.apache.org/confluence/display/solr/Spatial+Search

I adjusted CHANGES.md just now to point out you should use the ENVELOPE syntax in worldBounds.  I'm working on various updates to the Solr ref guide & Solr wiki now -- in progress.
 
What's going on with the documentation by the way? It's so scattered. Can we kill some of it to force people to the right places? You know what I mean?

Yeah, it's a mess :-(  The Solr ref guide is the official documentation for Solr and it's only modifiable by committers (like me).  But it's newer documentation compared to other sources so it is not as comprehensive.  At least it's cleaner and more approachable.  The older MoinMoin wiki was the defacto documentation but it's transitioning not to be anymore -- a slow and gradual process.  It is where more community advice tips & tricks go.  It holds lots of details not in the ref guide -- definitely true for spatial.
 
Would you be opposed to including some basic Solr field types on the help page there on github? I think you can be sure most people read that page at least. There also isn't really anything on the new switches (validationRule, datelineRule, etc.). These options are very hot BTW.

Ah, definitely *not* GitHub here because Spatial4j is ostensibly independent of Lucene-spatial, and definitely of Solr / ElasticSearch which is another layer away.  I think as long as there is a link in Solr's default example schema next to the field type for more information -- that's good.  The sore point is that the current link to  https://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 could use a refresher and perhaps migration into the Ref guide.  Again, I'm in-progress today with some amount of this activity.
 
I still can't get it to run though with my custom worldBounds. Here's my field definition and the error it generates. I'm guessing but it would seem that the SpatialContextFactory is trying to instantiate a ShapeParser in order to parse the worldBounds line but ends up passing in a SpatialContext instead of a JtsSpatialContext? Does that make sense? If I kill the worldBounds line, it starts up fine.

So did you swap out Spatial4j 0.4 in for 0.3 into your existing Solr pre 4.7?  You don't *have* to change the worldBounds syntax to ENVELOPE by the way -- I'm trying to keep backwards compatibility.  But any way you should and you are... so the specific problem appears to be that your 3rd and 4th arguments to ENVELOPE need to be swapped.  The order is minX, maxX, maxY, minY  -- definitely not intuitive!  Blame OGC for that one.
 
-Bruce


        <!-- Agora Grid ~ 10cm accuracy -->
        <fieldType name="agathe_spatial_c" class="solr.SpatialRecursivePrefixTreeFieldType"
                spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
                units="degrees"
                geo="false"
                worldBounds="ENVELOPE(-1000, 1000, -1000, 1000)"
                maxDistErr="0.00009"
                distErrPct="0.025"
        />


~ David 

_______________________________________________
dev mailing list
[hidden email]
http://lists.spatial4j.com/listinfo.cgi/dev-spatial4j.com
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] spatial4j

dsmiley
Oh drat!  initWorldBounds() should call  newSpatialContext();.  I didn't test JTS in combo with a custom world bounds.  I may need to rush a fix for this for 0.4.1

On Tue, Feb 18, 2014 at 11:27 AM, Bruce Hartzler <[hidden email]> wrote:
I got the error on the initial run (with the old worldBounds format). The envelope argument order sucks but easily correctable after the error in the log, so that's ok.

I didn't look at the situation too closely but I did have to copy the initWorldBounds method down into JtsSpatialContextFactory in order to get it to work. My java isn't the strongest but I think what's happening is that initWorldBounds is initializing a SpatialContext in order to parse the worldBounds but it passes "this" (i.e. a SpatialContext) instead of a JtsSpatialContext down into the JtsSpatialContextFactory.

So it goes something like: 

JtsSpatialContextFactory.init -> SpatialContextFactory.init -> SpatialContextFactory.initWorldBounds -> and then this creates a SpatialContext (NOT a JtsSpatialContext) which it then passes down into JtsWktShapeParser which complains because it's not a JtsSpatialContext. I.e.:

Caused by: java.lang.RuntimeException: class com.spatial4j.core.io.jts.JtsWktShapeParser needs a constructor that takes: [SpatialContext{geo=false, calculator=CartesianDistCalc, worldBounds=Rect(minX=-1.7976931348623157E308,maxX=1.7976931348623157E308,minY=-1.7976931348623157E308,maxY=1.7976931348623157E308)}, com.spatial4j.core.context.jts.JtsSpatialContextFactory@19ded4c9]

I hope that makes sense. Once I move the initWorldBounds down into JtsSpatialContextFactory and have it generate a JtsSpatialContext, then the shape parser is happy and doesn't croak.

I hope all that made sense. I'm not sure if this is the best way of solving the problem though....

Here's the diff:

diff --git a/src/main/java/com/spatial4j/core/context/jts/JtsSpatialContextFactory.java b/src/main/java/com/spatial4
index 1c35d9b..f8b24fc 100644
--- a/src/main/java/com/spatial4j/core/context/jts/JtsSpatialContextFactory.java
+++ b/src/main/java/com/spatial4j/core/context/jts/JtsSpatialContextFactory.java
@@ -24,6 +24,7 @@ import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
 import com.vividsolutions.jts.geom.GeometryFactory;
 import com.vividsolutions.jts.geom.PrecisionModel;
 import com.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory;
+import com.spatial4j.core.shape.Rectangle;
 
 import java.util.Map;
 
@@ -116,4 +117,15 @@ public class JtsSpatialContextFactory extends SpatialContextFactory {
   public JtsSpatialContext newSpatialContext() {
     return new JtsSpatialContext(this);
   }
+
+  @Override
+  protected void initWorldBounds() {
+      String worldBoundsStr = args.get("worldBounds");
+      if (worldBoundsStr == null)
+          return;
+      
+      //kinda ugly we do this just to read a rectangle.  TODO refactor
+      JtsSpatialContext simpleCtx = new JtsSpatialContext(this);
+      worldBounds = (Rectangle) simpleCtx.readShape(worldBoundsStr);//TODO use readShapeFromWkt
+  }
 }


_______________________________________________
dev mailing list
[hidden email]
http://lists.spatial4j.com/listinfo.cgi/dev-spatial4j.com