public Envelope createEnvelope ( double [ ] coordinates ) throws TypeConversionException { if ( coordinates . length < 4 ) { throw new TypeConversionException ( "Not enough coordinates in inputstring" ) ; } else { double minX = Double . MAX_VALUE ; double minY = Double . MAX_VALUE ; double maxX = Double . MIN_VALUE ; double maxY = Double . MIN_VALUE ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { if ( i % 2 == 0 ) { if ( coordinates [ i ] < minX ) minX = coordinates [ i ] ; if ( coordinates [ i ] > maxX ) maxX = coordinates [ i ] ; } else { if ( coordinates [ i ] < minY ) minY = coordinates [ i ] ; if ( coordinates [ i ] > maxY ) maxY = coordinates [ i ] ; } } return new Envelope ( minX , minY , maxX , maxY ) ; } }
Creates an envelope based on a list of coordinates . If less than two coordinates are in the list a typeconversion exception is thrown . If more than two coordinates are in the list the minimum X - and Y - coordinates are searched .