AnsweredAssumed Answered

Points contained in envelopes that cross date-line - java

Question asked by lukepatrick on Apr 20, 2015
Latest reply on May 28, 2015 by lukepatrick

I'm using the ESRI Geometry Java API https://github.com/Esri/geometry-api-java

I want to construct an envelope and see if it contains certain points. It's possible the envelope crosses the International date line.

Here is some sample code I've tried:

    double lon = Double.parseDouble("179.99"); 
    double lat = Double.parseDouble("0");
    Point pt = new Point(lon, lat);
    double minlon = Double.parseDouble("170");
    double minlat = Double.parseDouble("-20");
    double maxlon = Double.parseDouble("-170");
    double maxlat = Double.parseDouble("20");
    Envelope ev = new Envelope(minlon, minlat, maxlon, maxlat);
    SpatialReference sr = SpatialReference.create(4326); // decimal degrees    
    boolean test = GeometryEngine.contains(ev, pt, sr);
    System.out.println(GeometryEngine.geometryToJson(sr, ev));
    assertTrue
("envelope containts point true", test);

The test fails, and if I check the print statement I get a json that has swapped my x-coordinates

    {"xmin":-170,"ymin":-20,"xmax":170,"ymax":20,"spatialReference":{"wkid":4326}}

Is there a different/better way to do this?

Outcomes