Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jts-dev] split a polygon or line at the antimeridian

Excellent point, Gary - thanks, I missed that.

So to do this in JTS, implement a CoordinateSequenceFilter class providing the transformation suggested.  Apply this to copies of the geodetic geometries (unless you are sure that it is ok to alter the original geometry objects).

On Tue, Sep 26, 2017 at 4:17 AM, Gary Lucas <gwlucas@xxxxxxxxxxxxx> wrote:

Depending on how you want to define your coordinate system, one problem you face here is that the transform from [-180, 180) to [0, 360) will not be affine.  In particular, there is a discontinuity at the prime meridian, where the coordinate 1 stays 1, while -1 becomes 179.   So the AffineTransform class will not work for you .

 

I always handle this thing in code, writing my own transform class.  If you can count on longitude being in the range -180 <= longitude < 180, it’s pretty simple

 

        longitude = (longitude<0?longitude+180:longitude);

 

If you have to deal with coordinates out of range, I use the following though I’m sure it could be done a bit more elegantly

 

    static public double to360(double c) {

        double coordinate = 0;

        if (c < 0.0) {

            coordinate = ((-c) % 360);

            if (coordinate != 0) {

                coordinate = 360 - coordinate;

            }

        } else {

            coordinate = c % 360;

        }

        return coordinate;

    }

 

 

From: John Cartwright - NOAA Federal [mailto:john.c.cartwright@noaa.gov]
Sent: Monday, September 25, 2017 7:20 PM
To: jts-dev@xxxxxxxxxxxxxxxx
Subject: [jts-dev] split a polygon or line at the antimeridian

 

Hello All,

 

I feel like this is a common question but don't seem to find a good answer.  

 

I'm trying to split a simple shape at the antimeridian to form a multipart geometry.  My general approach was to construct two clipping polygons for the eastern and western hemispheres and intersect them with the target geometry.

 

Can someone suggest a better approach to doing this with JTS or GeoTools?

 

Related question - it seems that I need to shift the geometries from a -180 to 180 coordinate space to a 0 to 360 coordinate space in order to perform some of the calculations.  Is AffineTransformation the best way to approach this?  Any examples of using it for this purpose?

 

Thanks for any help you can provide!

 

--john

 


_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.locationtech.org/mailman/listinfo/jts-dev



Back to the top