Nodes inside a Spatial Envelope across lng 180 / -180

50 views
Skip to first unread message

Yuval

unread,
Aug 1, 2012, 5:02:45 PM8/1/12
to ne...@googlegroups.com
I am using the following code to retrieve nodes that fall within a boundary. 
bounds is supplied by google maps.

        Envelope bbox = new Envelope(bounds.lngNortheast, bounds.lngSouthwest, bounds.latNortheast, bounds.latSouteWest);
        Geometry geometry = spatialLayer.getGeometryFactory().toGeometry(bbox);
        GeoPipeline results = GeoPipeline.startWithinSearch(spatialLayer, geometry);


This works well when both west and east are within the same hemisphere (western or eastern).
However, when I try to load nodes that fall across hemispheres the Envelope sorts them to always include lng 0 instead of lng 180

For instance a map showing japan and US will load nodes from europe but not from hawaii.
Is there a way to retrieve an area that crosses 180 (I can always fall back to retrieve it as two separate areas but would like to avoid thinking about it if possible).

Yuval


Peter Neubauer

unread,
Aug 2, 2012, 5:28:34 AM8/2/12
to ne...@googlegroups.com
Uhm,
probably a missing test case. I guess we haven't been covering that.
Mind adding one and try to fix it? Otherwise, maybe raise and issue...
Craig, Davide?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.

Yuval

unread,
Aug 2, 2012, 9:17:35 AM8/2/12
to ne...@googlegroups.com
I wouldn't know where to start :-)

+ I'm not sure it would be backward compatible as the Envelope object explicitly states the coords will be sorted.
In fact this comes from the vivid solutions code which made me think there is a way to "express" this kind of envelope 
in the vivid solution code but I couldn't find anything.
Once you get the envelope there is not much you can do as the coords are sorted so there is no way to know which 
area the user wants (east-west or west-east).

Peter Neubauer

unread,
Aug 2, 2012, 9:50:22 AM8/2/12
to ne...@googlegroups.com
Mmh,
then this might be an issue there and should be asked over at their
forums maybe? I would love you to report back if you find out
something!

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.


Yuval

unread,
Aug 2, 2012, 10:30:16 AM8/2/12
to ne...@googlegroups.com
I will. This is the workaround for now. SpatialBounds is the logical area which I'm trying to convert to an Envelope. I break it down into two areas, and query each one individually
 (I must admit I am posting it here partly because it is the best function name ever).

    private static List<SpatialBounds> itsTheEndOfTheWorld(SpatialBounds bounds) {
        List<SpatialBounds>list = new ArrayList<SpatialBounds>();
        if (bounds.lngSouthwest > 0 && bounds.lngNortheast < 0) {
            list.add(new SpatialBounds(bounds.latSouthwest, bounds.lngSouthwest, bounds.latNortheast, 180));
            list.add(new SpatialBounds(bounds.latSouthwest, -180, bounds.latNortheast, bounds.lngNortheast));
        } else {
            list.add(bounds);
        }
        return list;

Peter Neubauer

unread,
Aug 2, 2012, 10:34:38 AM8/2/12
to ne...@googlegroups.com
Haha,
that name rocks. We have too few funny eastereggs in the code. More like that!

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.


Yuval

unread,
Aug 9, 2012, 3:12:42 AM8/9/12
to ne...@googlegroups.com
I tried to find their forum - dead for many years - or contact them - no reply. It looks a rather dead project.

Is there another way to do spatial queries without using the vivid code or is it the core geo indexing engine?

(also the endoftheworld function still has unhandled edge cases).

Craig Taverner

unread,
Aug 14, 2012, 5:53:16 AM8/14/12
to ne...@googlegroups.com
If it is JTS you are talking about, it is still alive and kicking, being maintained by the original author, Martin Davis, at his consulting firm (no longer part of vivid solutions). Take a look at http://tsusiatsoftware.net/jts/main.html. There is a mailing list and links to sourceforge. The most recent release was 1.12 in November 2011 (while the last vivid solutions release 1.8 looks like it was in 2006).

I believe that since neo4j-spatial depends on geotools 8.0, it should then also contain JTS 1.12, the latest release.

Unfortunately google still ranks the vividsolutions page higher. I should think they should redirect to the new location.
Reply all
Reply to author
Forward
0 new messages