public static Geometry toPolygon(byte[] bytes, int srid) throws SQLException, IOException {
        if(bytes==null) {
            return null;
        }
        WKBReader wkbReader = new WKBReader();
        try {
            if(GeometryMetaData.getMetaDataFromWKB(bytes).geometryType != GeometryTypeCodes.POLYGON) {
                throw new SQLException("Provided WKB is not a Polygon.");
            }
            Geometry geometry = wkbReader.read(bytes);
            geometry.setSRID(srid);
            return geometry;
        } catch (ParseException ex) {
            throw new SQLException("ParseException while evaluating ST_PolyFromWKB",ex);
        }
    }
public static Geometry toPolygon ( byte [ ] bytes , int srid ) throws SQLException , IOException { if ( bytes == null ) { return null ; } WKBReader wkbReader = new WKBReader ( ) ; try { if ( GeometryMetaData . getMetaDataFromWKB ( bytes ) . geometryType != GeometryTypeCodes . POLYGON ) { throw new SQLException ( "Provided WKB is not a Polygon." ) ; } Geometry geometry = wkbReader . read ( bytes ) ; geometry . setSRID ( srid ) ; return geometry ; } catch ( ParseException ex ) { throw new SQLException ( "ParseException while evaluating ST_PolyFromWKB" , ex ) ; } }
@param bytes WKB
@param srid SRID
@return Geometry instance of null if bytes are null
@throws SQLException Wkb parse exception