public static Polygon [ ] buffer ( Geometry [ ] geometries , SpatialReference spatialReference , double [ ] distances , boolean toUnionResults ) { // initially assume distances are in unit of spatial reference double [ ] bufferDistances = distances ; OperatorBuffer op = ( OperatorBuffer ) factory . getOperator ( Operator . Type . Buffer ) ; if ( toUnionResults ) { SimpleGeometryCursor inputGeometriesCursor = new SimpleGeometryCursor ( geometries ) ; GeometryCursor result = op . execute ( inputGeometriesCursor , spatialReference , bufferDistances , toUnionResults , null ) ; ArrayList < Polygon > resultGeoms = new ArrayList < Polygon > ( ) ; Geometry g ; while ( ( g = result . next ( ) ) != null ) { resultGeoms . add ( ( Polygon ) g ) ; } Polygon [ ] buffers = resultGeoms . toArray ( new Polygon [ 0 ] ) ; return buffers ; } else { Polygon [ ] buffers = new Polygon [ geometries . length ] ; for ( int i = 0 ; i < geometries . length ; i ++ ) { buffers [ i ] = ( Polygon ) op . execute ( geometries [ i ] , spatialReference , bufferDistances [ i ] , null ) ; } return buffers ; } }
Calculates a buffer polygon for each geometry at each of the corresponding specified distances . It is assumed that all geometries have the same spatial reference . There is an option to union the returned geometries .